
-----------------------------------
acc_minion
Wed Nov 26, 2003 7:22 pm

un-crackable encyrption? possible?
-----------------------------------
Hello,

I am trying to make a program that will encrypt and decrypt, I have the very basic encryption found on this site;

EDIT:  line  to 


   var text : string
    var codeword : string := ""
    var newletter : string

    put "Word to Encrypt: " ..
    get text : *

    for i : 1 .. length (text)

        newletter := chr (ord (text (i)) + 5)
        codeword := codeword + newletter

    end for

    put "Coded word: ", codeword, ""


However, I need this as a very complex version of the chr (ord ...) command taht will encrypt a letter into binary and then flip the binary code, then I need to be able to decrypt that code.

ie:
 Enter word:  blahblah
Word Encoded:  100110101010101 (or what ever)
;then;
Enter Coded Word: 100110101010101 (or what ever)
 Word UnCoded:  blahblah

Is this actually possible?

-----------------------------------
Mazer
Wed Nov 26, 2003 8:06 pm


-----------------------------------
ok... try this
note that it is necessary to return the value of encrypt as a string in order to keep any 0's at the beginning of the binary representation of a character's ascii value, which means any string you want to encrypt can't be more than 31 characters long.

so if you're trying to encrypt the contents of a file, just make sure the information is stored on lines of less than 32 characters.


% canges a line of reversed binary digits into understandable text
function decrypt (BINline : string) : string 
    var newline, num : string := ""

    for i : 1 .. length (BINline) by 8 % go through the whole string 8 bits (one byte) at a time
        for decreasing j : i + 7 .. i % set num to the reverse of the byte
            num += BINline (j)
        end for
        newline += chr (strint (num, 2)) % convert the byte to base 10 and use the ascii code to get the character
        num := "" % just reset num to nothing
    end for
    result newline % result the decrypted string
end decrypt

% changes a line of text into a line of reversed binary digits representing the ascii value of the string
function encrypt (TEXTline : string) : string 
    var newline, num : string := ""

    for i : 1 .. length (TEXTline) % go through the whole string, one character at a time
        num := intstr (ord (TEXTline (i)), 0, 2) % convert character to it's ascii value, then convert that to binary and store in num
        num := repeat ("0", 8 - length (num)) + num % add 0's to the end of the binary number as necessary (in case the number is less than 128 and therefore less than 8 digits)
        for decreasing j : 8 .. 1 % loop from the end of the binary number to the front, in order to reverse it
            newline += num (j) % add it to the newline string
        end for
    end for
    result newline % result the encrypted string for use in the decrypt function
end encrypt

put decrypt (encrypt ("1234567890123456789012345678901"))
%put decrypt (encrypt ("12345678901234567890123456789012")) % 