Thread: hashing a string

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    hashing a string

    Hello i was wondering if the following code is easily reversible:
    PHP Code:
    string jhash(string str)
    {
        
    unsigned int i;
        for(
    0str.length()-1i++)
            
    str[i] >>= str[i+1];
        for(
    1str.length(); i++)
            
    str[i] += str[i-1];
        for(
    0str.length()-1i++)
            
    str[i] <<= str[i+1];
        for(
    1str.length(); i++)
            
    str[i] ^= str[i-1];
        return 
    str;


    Thanks for your help.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    No its not reversable at all.
    Using the shift operator >> loses bits.
    If you remove the 2 loops that use shift operators then the hashing can be reversed.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    ok thanks

    alright, i just wanted to make a quick unreversible string hash for use in an application i'm working on : )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM