Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[AHK_L] Crypt - ahk cryptography class (Encryption, Hashing)


  • Please log in to reply
83 replies to this topic
  • Guests
  • Last active:
  • Joined: --
Any plans for publickey / private key?

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
for now - no, may be later...

S0und
  • Members
  • 100 posts
  • Last active: Apr 08 2015 10:07 AM
  • Joined: 16 Feb 2007
Is there a way, to reduce (?) the length of the encoded string? My plan is to create an encoded datamatrix barcode.

The original string is the same in both example.

1)
with FileEncrypt / FileDecrypt, my encoded string looks like this: bi_híG7hR–&™ÿßöúM«s^`J¥ºAÇ–ðJïAš»{" and then encoded it to base64, which looks like this: YmlfEWgS7Uc3aFKWJpn/3/b6TRmrc15gSqW6QceW8ErvQZq7eyI=

2)
with StrEncrypt / StrDecrypt, my encoded string looks like this: "623054240824EC7708622FA423ACFFD2F6C9361493415F514D8BBA75E3A7FA47D534A3D5304B80EFAD591DB1E536A9EC5FDE4BA42A1C8D0DCAB3956B975791FBC1FBEC8EDE6D"

i would like to use StrEncrypt / StrDecrypt, but the encoded string is a bit long. Compared to FileEncrypt + base64.

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
Yep, you'r right, base64 is better than hex. Actually i already changed this, just forgot to update the distrib. Thanks for the reminder.
It is updated now, redownload

Wicked
  • Members
  • 504 posts
  • Last active: Nov 18 2018 02:17 AM
  • Joined: 07 Jun 2008
I'm assuming it's my Unicode or something, but I'm using:
Crypt.Hash.StrHash("lol")
and getting:
fc33e60a7ffa718818c739265c415851
where I should be getting:
9cdfb439c7876e703e307864c9167a15

Does anybody know why this is? How can I fix this?

I can get this:
MD5( V ) { ; www.autohotkey.com/forum/viewtopic.php?p=376840#376840
 VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", UInt,&MD5_CTX )
 DllCall( "advapi32\MD5Update", UInt,&MD5_CTX, A_IsUnicode ? "AStr" : "Str",V, UInt,StrLen(V) ), DllCall( "advapi32\MD5Final", UInt,&MD5_CTX )
 Loop % StrLen( Hex:="123456789ABCDEF0" )
  N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
Return MD5
}
to work, but I require a PW like in this Crypt. :).

3nL8f.png


Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
looks like you have found a small shitty bug :) i forgot truncate null from the end of the string...
the new version uploaded, please try it
thank you!

  • Guests
  • Last active:
  • Joined: --
Amazing piece of work! Thanks for releasing this :)


I was hoping someone could answer a question I have about something.

When I run this:

#Include Crypt.ahk
#Include CryptConst.ahk
#Include CryptFoos.ahk

FileEncoding,UTF-16
FileAppend,test,testBOM.txt

Msgbox % Crypt.Hash.FileHash("testBOM.txt")


WinMD5sum and a linux based md5sum give me

f5d7d6670188e45b780ded0dd3ebb41b

but from AHK (latest unicode x86) I get

c8059e2ec7419f590e79d7f1b774bfe6

If you comment out the fileencoding line, the values match between the 3 programs.

Is there something I'm doing wrong (or need to do), or is this a bug?

Thanks!

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
Hello
found a bug, - for some reason ( beyond my uderstanding of things, probably ) FileOpen function puts position of pointer to 2 if that file has utf-16 encoding
thats why hash was incorrect
anyway, it's fixed now and you may re-download new version

thank you for finding it

IsNull
  • Moderators
  • 990 posts
  • Last active: May 15 2014 11:56 AM
  • Joined: 10 May 2007
Hi Deo,

Thanks for your great project and migration to AHK_L.

I just looked over your code and noticed your interesting way of defining constants. Using AHK_L, you can define them very easily as static Members of any class. This will simulate some kind of Enum:

Your current implementation of CryptConst...
CryptConst(name)
{
ALG_CLASS_ANY := (0)
ALG_CLASS_SIGNATURE := (1 << 13)
ALG_CLASS_MSG_ENCRYPT := (2 << 13)
ALG_CLASS_DATA_ENCRYPT := (3 << 13)

...

StringReplace,name,name,`n,`,,1				;replacing new lines with comma
	IfInString, name,,
	{
		arr := {}
		StringSplit,const,name,`,,%A_TAB%%A_SPACE%`n
		loop,%const0%
		{
			v := const%A_Index%
			if !v
				continue
			arr[v] := %v%
		}
		return arr
	}
	else
	{
		p := %name%
		if (p = "")
			p = err
		return p
	}
}
n := CryptConst("ALG_CLASS_ANY")



...would become like this:
class CryptConst
{
static ALG_CLASS_ANY := (0)
static ALG_CLASS_SIGNATURE := (1 << 13)
static ALG_CLASS_MSG_ENCRYPT := (2 << 13)
static ALG_CLASS_DATA_ENCRYPT := (3 << 13)
}
n := CryptConst.ALG_CLASS_ANY

This leads to better readable code IMHO :)¨


btw:

for some reason ( beyond my uderstanding of things, probably ) FileOpen function puts position of pointer to 2 if that file has utf-16 encoding

It probably skips the BOM?

IsNull
  • Moderators
  • 990 posts
  • Last active: May 15 2014 11:56 AM
  • Joined: 10 May 2007
Its me again. To use your script in AHK_L Ascii, you should fix your Base64 decoding.

Replace your b64Decode-function in CryptFoo.ahk with this and it works for all versions :)
b64Decode( b64str, ByRef outBuf )
{
   static CryptStringToBinary := "crypt32\CryptStringToBinary" (A_IsUnicode ? "W" : "A")

   DllCall( CryptStringToBinary, "ptr", &b64str, "UInt", 0, "Uint", 1, "Ptr", 0, "UInt*", outLen, "ptr", 0, "ptr", 0 )
   VarSetCapacity( outBuf, outLen, 0 )
   DllCall( CryptStringToBinary, "ptr", &b64str, "UInt", 0, "Uint", 1, "Ptr", &outBuf, "UInt*", outLen, "ptr", 0, "ptr", 0 )

   return outLen
}


Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
IsNull
Thanks, man, i've uploaded changes

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
download link updated
someone tried it at apathysoftworks.com/ahk/Crypt.zip and its there now :)

Elderon
  • Members
  • 36 posts
  • Last active: Apr 08 2014 04:16 PM
  • Joined: 17 Aug 2012
Hi Deo

I am having trouble with your functions, It works fine only if I use AHK_L Unicode64. If I use AHK_L Unicode32 the "imports" cannot be opened...

My understanding was that this would work for both versions(see first post).
I use AutoHotKey_l!
Windows 7 Ultimate x64
I don't like DropBox, try SugarSync instead.
while(!(succeed = try()));

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
hello
which message exactly do you get?

Elderon
  • Members
  • 36 posts
  • Last active: Apr 08 2014 04:16 PM
  • Joined: 17 Aug 2012

Error at line 5.

#Include file "CryptConst.ahk" cannot be opened.

The program will exit.


If I rearrange the imports they all show the same message but Crypt or CryptFoos instead of CrypConst.
I use AutoHotKey_l!
Windows 7 Ultimate x64
I don't like DropBox, try SugarSync instead.
while(!(succeed = try()));