Jump to content

Encryption


Alek
 Share

Recommended Posts

I was trying to make a new encryption functions and here it is, not sure how secure it is and I have no idea why it works :)

$String = _Encrypt('test','123',4)
ConsoleWrite('Encrypted: ' & $String & @CRLF)
ConsoleWrite('wrong key: ' & _Encrypt($String,'321',4) & @CRLF)
ConsoleWrite('wrong lvl: ' & _Encrypt($String,'123',3) & @CRLF)
ConsoleWrite('Decrypted: ' & _Encrypt($String,'123',4) & @CRLF)

Func _Encrypt($s_String,$s_Key = '1', $s_Level = 1)
    Local $s_Encrypted, $s_kc = 1
    If StringLen($s_Key) = 0 Or $s_Level < 1 Then Return 0
    
    $s_Key = StringSplit($s_Key,'')
    $s_String = StringSplit($s_String,'')
    
    For $x = 1 To $s_String[0]
        If $s_kc > $s_Key[0] Then $s_kc = 1
        $s_Encrypted &= Chr(BitXOR(Asc($s_String[$x]),Asc($s_Key[$s_kc])*$s_Level))
        $s_kc += 1
    Next
    
    Return $s_Encrypted
EndFunc
Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

And decryption?

run the encrypted string trough the encrypt function again and it will be decrypted.

Kinda why I'm a bit confused about it :)

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

So, you made an encryption algorithm, and don't understand how you made it?

All it does is an XOR of every character of the original string with a letter from the key, with the key repeating for the entire length of the input string.

My guess: you found this somewhere else, probably in a different language, and translated it to work here. Not a bad start to learning, everyone has to learn somewhere.

It's only as secure as the key you use to encrypt with. Ideally, you'd want to use a key the same length of the input string, and only use it once. That would make this the same as a One-Time Pad (google/wikipedia that, and you'll see why you want that).

Link to comment
Share on other sites

I'm not an encryption expert, but using the last character of the password as a key for every character in the entire string (except the first few characters) does not seem very effective to me. I believe it should be this:

$String = _Encrypt('The quick brown fox jumps over the lazy dog','123',4)
ConsoleWrite('Encrypted: ' & $String & @CRLF)
ConsoleWrite('wrong key: ' & _Encrypt($String,'321',4) & @CRLF)
ConsoleWrite('wrong lvl: ' & _Encrypt($String,'123',3) & @CRLF)
ConsoleWrite('Decrypted: ' & _Encrypt($String,'123',4) & @CRLF)

Func _Encrypt($s_String,$s_Key = '1', $s_Level = 1)
    Local $s_Encrypted, $s_kc = 1
    If StringLen($s_Key) = 0 Or $s_Level < 1 Then Return 0
   
    $s_Key = StringSplit($s_Key,'')
    $s_String = StringSplit($s_String,'')
   
    For $x = 1 To $s_String[0]
        $s_kc = Mod($x,$s_Key[0])
        $s_Encrypted &= Chr(BitXOR(Asc($s_String[$x]),Asc($s_Key[$s_kc])*$s_Level))
    Next
   
    Return $s_Encrypted
EndFunc
Link to comment
Share on other sites

As stated before, your method is only as secure as the key used to encrypt the message is.

But one problem that i have noted with similar methods to this, that i've seen, is that if you use one key to encrypt a message with (e.g. 'aaaa') and then use another, similar key to decrypt the message with (e.g. 'aaab') it will actually return parts of the original string :P (in this case, the first 3 bytes of every 4 byte chunk)

I've actually created my own encryption/decryption + checksumming methods as well ... just because I got bored.

IMHO I think it's alright, but I'd have no idea because i'm not a cryptanalyst but oh well :P

It's a bit complex, probably overkill, but i wanted to ensure that any output would not have a repeated pattern in it and that the weakness previously mentioned was taken care of :)

Download: _TwoWayCrypt.au3

Note: i do not intend to hijack this thread, i just wish to share my own efforts towards some kind of encryption method :D

My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website

Link to comment
Share on other sites

  • 3 weeks later...

nice script! weird.. I dont understand it either..

The XOR encryption algorithm is regarded as inherently insecure. Even without knowledge of the key, it is easy and quick to retrieve the plain text of the message using brute force methods.

However, it does give an insight into how encryption algorithms work and is useful as an academic exercise.

As to how it works? The plain text is encrypted against the key according to some set pattern. Decryption is the exact reverse of encryption, as the XOR value of some character is always going to be the same, given the same key, and vice versa. For example, suppose the XOR of the character 'A', with our key becomes the character 'Z', then XORing 'Z' with the same key will produce 'A'.

XOR is a logical operation, meaning eXclusive OR. It is too long ago since I studied logic gates, so I can't give you the logic table, but I am sure someone out there can ...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...