Page 1 of 1

C to LiveCode Conversion

Posted: Wed Dec 16, 2015 9:55 pm
by ToddFabacher
Sorry to bother the list, but I don't know how to do Xor in LiveCode. I have an app deadline of this week and I can't figure now to do a byte Xor conversion. We converted an Objective C app to LiveCode, I have done ALL of the code except a small encryption function. I can't figure how to convert using LiveCode. Any help would be appreciated.

Best,

Todd

Code: Select all


- (NSString *) encryptString : (NSString *)sInput{

  

    NSInteger len;     //store the length of input string

    const NSString *key =@"keycode";

    

    //create data object from the string

    NSData *data= [sInput dataUsingEncoding:NSUTF8StringEncoding];

    NSData *data1= [sInput dataUsingEncoding:NSUTF8StringEncoding];

    

    //Get pointer to data to obfuscate

    char *dataPtr = (char *) [data bytes];

    char *tempPtr= (char*) [data1 bytes];

    

    //get pointer to key data

    char *keyData =(char *) [[key dataUsingEncoding:NSUTF8StringEncoding] bytes];



    //points to each char in seqeunce in the key

    char *keyPtr =keyData;

    int keyIndex =0 ;

    len=[data length];

    //for each character in data , xor with current value in key

    for (int x=0; x< len; x++){

        *tempPtr++ = *dataPtr++ ^ *keyPtr++;

       

        if(++keyIndex == [key length])

            keyIndex = 0,keyPtr =keyData;

    }

    return [[NSString alloc] initWithData:data1 encoding:NSUTF8StringEncoding];

}

Re: C to LiveCode Conversion

Posted: Wed Dec 16, 2015 11:04 pm
by [-hh]
          
.

Re: C to LiveCode Conversion

Posted: Thu Dec 17, 2015 4:07 am
by FourthWorld
If I'm reading that C code corrrectly, it seems it's merely xor'ing the plaintext with the key, but while that can be useful for simple masking it's not very secure. Effectively it merely creates an extended form of Caesar cipher, in which the source text can be found with automated analysis - and once found, the password used to encrypt it is also discovered.

A slightly stronger variant is this algo that uses xor with md5, operating on compressed text to further mask patterns:
http://livecodejournal.com/tutorials/ha ... s-005.html

But that's not especially strong either, useful for education purposes (the xor use there may be helpful for you), but not a good choice for truly securing data.

Better still would be to let the pros do the work and use LC's built-in encrypt and decrypt functions, providing access to a wide range of industrial-strength encryption algos.
XOR is trivial to break, requiring seconds at most, whereas DES takes hours to crack, and Blowfish would take us past the expected lifetime of the sun.
http://www.kuro5hin.org/?op=displaystor ... 174741/423