www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: [RESOLVED] Caeser cipher help - excluding non-alphabetic characters

  1. #16
    Join Date
    Jan 2014
    Location
    Boston, Massachusetts
    Posts
    66
    That outputs "De, ^k^!" when I use 4 as the offset, encode once, decode once (which the first time works fine), then decode again ($ascii-- produces the same result). It should output "De, xkx!".

  2. #17
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,617
    When decoding (decrementing the ascii value) the turnover points are 64 and 96 (at the other end of the valid ranges). See my "negative offset" comment in the OOP example.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #18
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,502
    How about putting in to an array all the letters you want A-Z a-z and then creating an array of values that can be used as keys and merged with the array_combine function.

    Something like this (not checked if it would produce desired results but...)
    PHP Code:
    $asciiArray = array();
    $keysArray = array();
    // make ascii array
    for($ascii=65$ascii<=122$ascii++)
        if(
    $ascii<=90 or $ascii >=97){
            
    // we're in range
            
    $asciiArray[] = chr$ascii );
            
    // make keys
           
    $keysArray[] = chr$ascii);
    }
    shuffle( &$keysArray);
    $code array_combine($keysArray,$asciiArray); 
    then if you need to send the sequence of the array with the message as the cipher key, you can serialize the array and base64 or AES encode it.
    Last edited by \\.\; 02-02-2014 at 05:12 PM.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  4. #19
    Join Date
    Jan 2014
    Location
    Boston, Massachusetts
    Posts
    66
    A million thanks, seriously!!

  5. #20
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,502
    OK, slight error with

    shuffle( &$keysArray);

    it should be

    shuffle( $keysArray);

    I tried it, serialized the array for the keys and code, base64_encoded it then tagged on the code, the breaking apart is easy if you add in a delimiter value like a line return

    Code:
    YTo1Mjp7czoxOiJ3IjtzOjE6IkEiO3M6MToiVyI7czoxOiJCIjtzOjE6ImoiO3M6MToiQyI7czoxOiJCIjtzOjE6IkQiO3M6MToiZCI7czoxOiJFIjtzOjE6ImkiO3M6MToiRiI7czoxOiJYIjtzOjE6IkciO3M6MToiSCI7czoxOiJIIjtzOjE6IlYiO3M6MToiSSI7czoxOiJFIjtzOjE6IkoiO3M6MToidiI7czoxOiJLIjtzOjE6IkMiO3M6MToiTCI7czoxOiJJIjtzOjE6Ik0iO3M6MToicCI7czoxOiJOIjtzOjE6IlQiO3M6MToiTyI7czoxOiJaIjtzOjE6IlAiO3M6MToiTSI7czoxOiJRIjtzOjE6Im4iO3M6MToiUiI7czoxOiJKIjtzOjE6IlMiO3M6MToiTyI7czoxOiJUIjtzOjE6InUiO3M6MToiVSI7czoxOiJzIjtzOjE6IlYiO3M6MToidCI7czoxOiJXIjtzOjE6IkwiO3M6MToiWCI7czoxOiJOIjtzOjE6IlkiO3M6MToiUiI7czoxOiJaIjtzOjE6ImYiO3M6MToiYSI7czoxOiJ6IjtzOjE6ImIiO3M6MToiZSI7czoxOiJjIjtzOjE6ImciO3M6MToiZCI7czoxOiJvIjtzOjE6ImUiO3M6MToiSyI7czoxOiJmIjtzOjE6ImwiO3M6MToiZyI7czoxOiJiIjtzOjE6ImgiO3M6MToiWSI7czoxOiJpIjtzOjE6ImsiO3M6MToiaiI7czoxOiJoIjtzOjE6ImsiO3M6MToiciI7czoxOiJsIjtzOjE6IkQiO3M6MToibSI7czoxOiJVIjtzOjE6Im4iO3M6MToibSI7czoxOiJvIjtzOjE6InkiO3M6MToicCI7czoxOiJjIjtzOjE6InEiO3M6MToiRyI7czoxOiJyIjtzOjE6IngiO3M6MToicyI7czoxOiJxIjtzOjE6InQiO3M6MToiUSI7czoxOiJ1IjtzOjE6IlAiO3M6MToidiI7czoxOiJBIjtzOjE6InciO3M6MToiUyI7czoxOiJ4IjtzOjE6ImEiO3M6MToieSI7czoxOiJGIjtzOjE6InoiO30=
    Hcgge AelgE, WkFV VkeUgE hc cRqeEcE AkFgc 123456789 FV ReW...
    it is a bit heavy on the code length for short messages but each time you use the coder, the cipher changes randomly
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles