Sign in to follow this  
Followers 0
CHronologist

OneTimePad

4 posts in this topic

I wanted to create an improved OneTimePad function, especially for shorter strings like username and password combinations. So I added two features:

1) I didn't use the ASCII or UNICODE signs, but a pool inside the function. This results in less possibility to decrypt the code, because an attacker would exspect a relation between the signs based on the ASCII code, but since you can shuffle the order of the sign pool this is not given.

2) The order of the sign pool shifts while encrytping, in my code only by placing the last sign at the beginning, but you theoretically could use any other reversable algorithm and an attacker that doesn't know about it, won't find a way to decrypt. So it's like a second key to the code.

#include <string.au3>

Func OneTimePad($Text, $Key, $Flag = 1)
    Local $Encrypted = "", $Fullkey = "", $Tab = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", $len
    $len = StringLen($Text)
    If $Flag <> 1 Then $Flag = -1
    If $Flag = -1 Then 
        For $i = 1 to $len + 1
            $Tab = StringRight($Tab, StringLen($Tab) - 1) & StringLeft($Tab, 1)
        Next
        $Text = _StringReverse($Text)
    EndIf   
    For $i = 1 to Int($len/StringLen($Key))
        $Fullkey &= $Key
    Next
    $Fullkey &= StringLeft($Key, $len - StringLen($Fullkey)) 
    For $i = 1 to $len
        If $Flag = 1 Then
            $Tab = StringRight($Tab, StringLen($Tab) - 1) & StringLeft($Tab, 1)
        Else
            $Tab = StringRight($Tab, 1) & StringLeft($Tab, StringLen($Tab) - 1) 
        EndIf   
        $Encrypted &= StringMid($Tab, Mod(StringInStr($Tab, StringMid($Text, $i, 1), 1) + $Flag * StringInStr($Tab, StringMid($Fullkey, $i, 1), 1) + 62, StringLen($Tab)), 1)
    Next
    If $Flag = -1 Then $Encrypted = _StringReverse($Encrypted)
    Return($Encrypted)  
EndFunc

Please tell me what you think. If it is an improvement or total crap. If it could be more simple or if there is a case it doesn't work (of course I tested everything that came to my mind).

Chronologist

Share this post


Link to post
Share on other sites



#4 ·  Posted (edited)

For the use, it should serve you in protecting your data. You call the function with the text you want to encrypt and the key you want to use, to decrypt an encrypted text call the function with the encrypted text, the key that were used, and the third argument as -1 and you should get back the original text.

@billthecreator, could you explain what you did when it didn't work, I can't figure out. Maybe you used a sign which is no in the sign pool like " ".

Edited by CHronologist

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0