C to LiveCode Conversion

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller

Post Reply
Posts: 280
Joined: Fri Jan 09, 2015 6:15 pm

C to LiveCode Conversion

Post by ToddFabacher » Wed Dec 16, 2015 9:55 pm

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.



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];


VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: C to LiveCode Conversion

Post by [-hh] » Wed Dec 16, 2015 11:04 pm

Last edited by [-hh] on Thu Dec 24, 2015 1:42 am, edited 1 time in total.
shiftLock happens

VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7929
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles

Re: C to LiveCode Conversion

Post by FourthWorld » Thu Dec 17, 2015 4:07 am

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
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Converting to LiveCode”