AutoHotkey Community

It is currently May 27th, 2012, 12:06 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: April 4th, 2011, 7:40 pm 
Offline

Joined: November 28th, 2010, 8:37 am
Posts: 48
Location: Wuxi, China
Hi Laszlo, this script is really hot!

I have just been testing it and it works very well, except that it does not seem to support Unicode characters such as Chinese text. I am using AutoHotkey_L which supports Unicode.

I was looking to make a tool to encrypt and decrypt selected text, for use on instant messaging applications within mainland China, thus enabling me and my friends to openly discuss any potentially sensitive topics without fear of being intercepted by big brother. You code worked reliably with ABCs, but when I tested it with Chinese text it failed to yield the original data.

As I don't fully understand the code and I am using it on a black-box basis, I can only humbly ask Laszlo or other savvy coders to add Unicode support.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2011, 7:48 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
RC4 is byte oriented, so you have to convert your Unicode string to a byte array, and process that. The result is also a byte array, not a Unicode string, so you have to transmit it coded to strings, e.g. in hex ASCII characters.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2011, 8:50 pm 
Offline

Joined: March 10th, 2011, 7:17 pm
Posts: 374
Laszlo

i know in the past you made some comments about AHK being obsolete and no longer supported or developed. have you see the changes that Lexikos has made in his v2 alpha release? i'm curious about your thoughts of the future of AHK given that it looks like v2 will be happening. you are one of my favorite posters and i use your scripts a lot (include this RC4 one).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2011, 9:18 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
(This is not the right section of the Forum, but I think a good direction with developing AHK is fixing its inconsistent syntax, numerous bugs, removing limitations, and add features, like dynamic expression evaluator, arrays and others, which make simple code more readable. AHKv2 is too fluid now for a firm opinion.

AHK_L: If I needed objects I could use Java, Python, C#..., with more support, more features, less bugs. I use pure AHK for automating tasks, like launching a program, auto-setting its parameters, capturing the results, pop up a GUI window to display them, with highlighting the important parts; or copy a figure to the clipboard, change to Word, paste it to the mouse position, resize the picture, add caption, move the cursor, etc.

IronAHK is promising, although it develops slowly. I hope someday to run IronAHK scripts in my DroidX. If Frink had better graphics and hotkeys, it would be an ideal replacement. For now I stick to the original AHK and solve more complex tasks in Python.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 29th, 2011, 10:41 pm 
Offline

Joined: April 20th, 2006, 5:11 pm
Posts: 75
Location: Vienna
Hi Laszlo!

I'm writing a new Script and it seems like your Encryption scrambles the Data after 164 chars (+ 4 A_Tab).

Basicly, my script creates 2 random-generated Passphrases (64 Chars).
The first Passphrase (salt) is encrypted with a Space Char (A_Space) and the second (password) is encrypted with the first.
Then on a Username are 5 Characters Attached (salt, char 1-5) and are encrypted with the password
The Password for the username (pwd) has also 5 chars attached (salt, char 10-15) and is encrypted with the password.
Furthermore, a URL is encrypted with the password.

All Data are seperated with a Char (can be `n, A_Space, A_Tab, ...) and then the entire String is encrypted again with a Space Char to obfuscate which data belongs to which part of the login.

password has 64 characters and will be encrypted 128 chars long, aswell as salt will be.
in my example the username has 10 chars, and will be encrypted 30 chars long
my password has 16 chars and will be encrypted 42 chars long.
then, my host-adress has originally 15 chars, but will be encrypted to 30 chars (which belongs to the 10 of the username) and finally, the entire string has 362 chars and is encrypted 725 chars long.

I assume you'll need some code, so there we go:

Thats the Loginfile-Creator
Code:
#Include, %A_ScriptDir%
#Include, rc4hex.ahk


Gui, Margin, 5, 5

Gui, Add, Text, xm ym w125 h20 , DynDNS Benutzername:
Gui, Add, Edit, xm+130 yp w230 hp vddns_user, abcdefghij

Gui, Add, Text, xm yp+25 w125 hp , DynDNS Passwort:
Gui, Add, Edit, xm+130 yp w230 hp vddns_passwd , 4rIYy|B\`%A0@?)rC

Gui, Add, Text, xm yp+25 w125 hp , DynDNS Host:
Gui, Add, Edit, xm+130 yp w230 hp vddns_host, xxxx.dyndns.org

Gui, Add, Text, xm yp+25 w125 hp , Speicherort:
Gui, Add, Edit, xm+130 yp w195 hp vfile ReadOnly, %A_ScriptDir%\masterplan
Gui, Add, Button, xp+200 yp w30 hp gChooseFile, ...

Gui, Add, Button, xm+130 yp+30 w110 h30 gGenerate Default, Generieren
Gui, Add, Button, xp+120 yp wp hp gCloseGUI, Beenden
Gui, Show, Center AutoSize, Remotedesktop Logincreator 0.1a
GuiControl, Focus, ddns_user
Return

CloseGUI:
GuiEscape:
GuiClose:
ExitApp

Generate:
Gui +OwnDialogs
Gui, Submit, NoHide
salt := GenerateRandomPasswd(64, "abcdefghijklmnopqrstuvwxyz"
                        . "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                        . "0123456789äöüÄÖÜ!?-+._")
enc_passwd := GenerateRandomPasswd(64)
auth := RC4txt2hex(   RC4txt2hex(salt, A_Space) "`n"
               . RC4txt2hex(enc_passwd, salt) "`n"
               . RC4txt2hex(ddns_user SubStr(salt, 1, 5), enc_passwd) "`n"
               . RC4txt2hex(ddns_passwd SubStr(salt, 10, 5), enc_passwd) "`n"
               . RC4txt2hex(ddns_host, enc_passwd), A_Space)

Msgbox, % liste := RC4txt2hex(salt, A_Space) "`n"
      . RC4txt2hex(enc_passwd, salt) "`n"
      . RC4txt2hex(ddns_user SubStr(salt, 1, 5), enc_passwd) "`n"
      . RC4txt2hex(ddns_passwd SubStr(salt, 10, 5), enc_passwd) "`n"
      . RC4txt2hex(ddns_host, enc_passwd)
Msgbox, % StrLen(liste)
authblock := CreateBlocks(auth, 64)

If FileExist(file)
   FileDelete, %file%
FileAppend, %authblock%, %file%
Msgbox, 64, Info, Das Loginfile wurde erstellt...
Return

ChooseFile:
Gui +OwnDialogs
FileSelectFile, file, S, , Bitte Speicherort angeben...
If Errorlevel
   Return
GuiControl, , file, %file%
Return

GenerateRandomPasswd(len, chars = "") {
   If !chars
      charset := "abcdefghijklmnopqrstuvwxyz"
            . "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            . "0123456789äöüÄÖÜ@<({[/=\]})"
            . ">!?$&#*-+.,;:_"
   Else
      charset := chars
   Loop, %len% {
      Random, r, 1, % StrLen(charset)
      pass .= SubStr(charset, r, 1)
   }
   Return, pass
}

CreateBlocks(str, blocklenght){
   blocked := ""
   len := Strlen(str)
   loop, % len / blocklenght
      blocked .= SubStr(str, ((A_index - 1) * blocklenght) + 1, blocklenght) "`n"
   blocked .= SubStr(str, len - Mod(len, blocklenght))
   return blocked
}


And a little test-authenticate-Script:
Code:
#Include, %A_ScriptDir%
#Include, rc4hex.ahk

; Authenticate

file := A_ScriptDir "\masterplan"

FileRead, encrypted, %file%
encrypted := RegExReplace(encrypted, "\R")
; Msgbox, %encrypted%      ; CHECK
decrypted_auth := RC4hex2txt(encrypted, A_Space)
;Msgbox, %decrypted_auth%
StringSplit, encrypted_data, decrypted_auth, `n
Msgbox, %encrypted_data0%`n`n%encrypted_data1%`n`n%encrypted_data2%`n`n%encrypted_data3%`n`n%encrypted_data4%`n`n%encrypted_data5%
decrypted_salt := RC4hex2txt(encrypted_data1, A_Space)
decrypted_passwd := RC4hex2txt(encrypted_data2, decrypted_salt)
decrypted_user := SubStr(RC4hex2txt(encrypted_data3, decrypted_passwd), 1, -5)
decrypted_pass := SubStr(RC4hex2txt(encrypted_data4, decrypted_passwd), 1, -5)
decrypted_host := RC4hex2txt(encrypted_data5, decrypted_passwd)

Msgbox, % "Salt = " decrypted_salt " - " StrLen(decrypted_salt) "`n"
      . "Passwort = " decrypted_passwd " - " StrLen(decrypted_passwd) "`n"
      . "Benutzer = " decrypted_user " - " StrLen(decrypted_user) "`n"
      . "Passwort = " decrypted_pass " - " StrLen(decrypted_pass) "`n"
      . "Host = " decrypted_host " - " StrLen(decrypted_host)
ExitApp



PS.: I scrambled all login data, but the length is the same.

A first error was that the tecnique I used before was buggy, so IsNull helped me out with the new CreateBlocks()-Function.
Before that change, not even the first password was decrypted...

So may you can help me out. I think it has something to do with your Encryption, but after trying your example I'm not so sure anymore.
But it's definitely weired that this error happens exactly after 164 chars plaintext.

PPS.: I'm using the latest version of AHK-Basic.


THXIA


EDIT: Hi again. Theres no error with your code, the mistake was the Block-Function.
Thanks to the guys from the german Forum (which I posted earlier) the error was found.

Code:
;authblock := CreateBlocks(auth, 64)
L := 64, P := 1 - L
While (P <= StrLen(auth))
   authblock .= SubStr(auth, P += L, L) . "`n"


It seems like that the Function duplicated a char while creating the blocked code so that the decryption cant work.

Thanks anyway.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 3rd, 2011, 11:28 pm 
Hi Laszlo!

This code is great! However, you name some crypto.dll's and built-in functions like this one that are better. Could you give us an example of one and how to use it?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2011, 12:18 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
start here: http://www.autohotkey.com/forum/viewtopic.php?t=23719


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: notsoobvious and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group