How to encrypt

Get help with using AutoHotkey and its commands and hotkeys
omar
Posts: 462
Joined: 22 Oct 2015, 17:56

How to encrypt

01 Jan 2021, 19:21

I have a 12 digit number: 133565828659

I want to encrypt this (and after decrypt).
What are my options?

I spent 20-30 minutes going through different options I found on Google.
One promising one from this link: https://github.com/aviaryan/autohotkey-scripts/blob/master/Functions/Encrypt.ahk

But this requires another file the guy wrote - this, I can't find.

IMPORTANT: I want the output to be the same length or shorter than the input.
Doesn't matter if we use characters - the end output doesn't have to be numbers.

Thanks.
omar
Posts: 462
Joined: 22 Oct 2015, 17:56

Re: How to encrypt

01 Jan 2021, 21:16

Looks great
I can't figure out how to use though
I've looked at the examples and it's not making sense!

For example:
MsgBox % Crypt.Hash.String("SHA1", "The quick brown fox jumps over the lazy dog")
; -> 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
How would one decrypt?

Then you have:
MsgBox % Crypt.Encrypt.String("AES", "CBC", "abcdefghijklmnop", "1234567890123456", "1234567890123456")
; -> Nn9CFFuC+/O84cV1NiwLYoyd25Z9nmWv16dIFKzf2b4=

and

MsgBox % Crypt.Decrypt.String("AES", "CBC", "Nn9CFFuC+/O84cV1NiwLYoyd25Z9nmWv16dIFKzf2b4=", "1234567890123456", "1234567890123456")
; -> abcdefghijklmnop

So that one, I get, I guess

But... I really needed something with a smaller output (or even 2 digits more would be OK).
Any chars are OK - but not + and / chars

Any ideas?

I see the code uses Microsoft dll's. What if someone doesn't have? Just wondering.

Thanks.
User avatar
jNizM
Posts: 2681
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: How to encrypt

04 Jan 2021, 06:32

1) Crypt.Hash.String()
Hashing (e.g. MD5 / SHA1 / SHA2) are one-way functions. You cannot decrypt them (only with brut-force or rainbow tables)

2) Crypt.Eecrypt.String()
You can use the "hexraw" parameter to get just letters and numbers (0-9 + A-F)
(e.g. MsgBox % Crypt.Encrypt.String("AES", "ECB", "133565828659", "1234567890123456",,, "HEXRAW"))

3) if you want some short stuff you can search the forum. there are a few custom enctyptions
[AHK] 1.1.33.02 x64 Unicode | [WIN] 10 Pro (Version 20H2) x64 | [GitHub] Profile
Donations are appreciated if I could help you
Rohwedder
Posts: 3944
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to encrypt

04 Jan 2021, 08:59

Hallo,
try:

Code: Select all

Number := 133565828659
Pass   := 123456789012
MsgBox,% Encrypt := Number^Pass
MsgBox,% Decrypt := Encrypt^Pass
omar
Posts: 462
Joined: 22 Oct 2015, 17:56

Re: How to encrypt

05 Jan 2021, 20:03

Thanks for the replies guys.

@Rohwedder wow
That looks pretty good. Just what I wanted!

Can you explain what's happening?
How does it work?
Is it this that's doing the work: ^ ?
I can't seem to search for it!

I'll use this.
But would love to know how and why it works!

EDIT: it doesn't work if the number starts with a 0.
So, if I have 0099823924, I need to get out the same, with the leading 0's.
I guess I could hack it by counting the number of digits and adding 0's at the beginning.
But that wouldn't seem right.
Any thoughts?
(Also, wondering if the pass has a zero at the beginning, does it matter?)

Thanks.
Rohwedder
Posts: 3944
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to encrypt

06 Jan 2021, 05:23

See https://www.autohotkey.com/docs/Variables.htm#operators
^ is bitwise-exclusive-or
These two functions should be more "robust":

Code: Select all

Global Pass := 12345678901234567
Number := 00133565828659
MsgBox,% Encrypt := Encrypt(Number)
MsgBox,% Decrypt := Decrypt(Encrypt)
Return
Encrypt(No)
{	
	Pass2 := SubStr(Pass, 1, Len:=StrLen(No)-1)
	Return, SubStr(Format("{:049X}", No^Pass2), -Len)
}
Decrypt(No)
{
	Pass2 := SubStr(Pass, 1, Len:=StrLen(No)-1)
	No := "0X" No
	Return, SubStr(Format("{:049u}", No^Pass2), -Len)
}
To keep the string lengths the length of Pass is adjusted.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Ioniq, jacek678, Xeo786, zvit and 52 guests