GML Highlighting provided by GameMaker.info
Back
 
#define caesar_cypher
//  caesar_cypher(text,shift);
//
//  Arguments:

//      text       the text you want encrypted, a string
//      shift      the letter shift, a number
//
//  Returns:
//      the encrypted (or decrypted) text as a string

//
//  Notes:
//      to decrypt, merely use a negative shift on the encrypted text:
//      if you used a shift of 4 to encrypt, use a shift of -4 to decrypt
//
//    Script by RoboBOT

var input,shift,i,num,output;
input=argument0;
shift=argument1;
output="";
if (shift<0) shift=26+(shift mod 26);
if (shift mod 26 = 0) return input;

for (i=1;i<=string_length(input);i+=1) {
    num=ord(string_char_at(input,i));
    if (num>64 && num<91) {

        if ((num-64+shift)/26!=(num-64+shift) div 26) {
            num=((num-64+shift) mod 26) + 64;
        } else num=90;
    } else {

        if (num>96 && num<123) {
            if ((num-96+shift)/26!=(num-96+shift) div 26) {

                num=((num-96+shift) mod 26) + 96;
            } else num=122;
        };
    };
    output+=chr(num);
};

return output;