SRL Archive - Research & Development Lounge

Cypher Encoder/Decoder.


Sandstorm

2009-10-02 00:47:15

What this does is creates a cypher set, then encodes it, then md5 hashes it, and then encodes the md5 hash. To decode it, it has to decode the hash once, then reverse the hash, and then decode it again. As a result of making a block of code that achieves this, it has to md5 hash each letter individually, so the strings get VERY long.

How to use:

Find a friend (or yourself), and choose a shared keyword. Place the keyword in the CodeWord constant slot, and then the string you wish to encrypt and decrypt, in the Encrypt constant slot, and then hit run.

If you're using the encrypter, it will give you a unique encrypted string (unique to your keyword), that only people who know the keyword will (in theory) be able to decode.

Encrypter:

program Hashdeencrypt;

const
codeword = 'fred';
encrypt = 'hello.';

Function Cypher(Codeword, ToEncrypt : string) : String;
var
return, C1, C2, Encrypting, Encrypted : string;
I : Integer;
begin
Return := CodeWord;
For I := 1 to length(Return) do
begin
if length(C1) < 25 then
begin
C1 := C1 + strget(Return, I);
end else
C2 := C2 + Strget(Return, I);
end;
C1 := Uppercase(C1);
C2 := Uppercase(C2);
For I := 40 to 90 do
begin
If length(C1) < 25 then
begin
If Pos(chr(I), C1) = 0 then
If Pos(chr(I), C2) = 0 then
C1 := C1 + chr(I);
end else
begin
If length(C2) < 25 then
begin
If Pos(chr(I), C1) = 0 then
If Pos(chr(I), C2) = 0 then
C2 := C2 + chr(I);
end;
end;
end;
Encrypting := uppercase(ToEncrypt);
For I := 1 to length(ToEncrypt) do
begin
If Pos(Strget(Encrypting, I), C1) <> 0 then
begin
Encrypted := Encrypted + Strget(C2, Pos(Strget(Encrypting, I), C1));
end else
begin
If Pos(Strget(Encrypting, I), C2) <> 0 then
begin
Encrypted := Encrypted + Strget(C1, Pos(Strget(Encrypting, I), C2));
end else
Encrypted := Encrypted + strget(Encrypting, I);
end;
end;
result := Encrypted;
end;

function ReverseMD5(MD5 : AnsiString) : AnsiString;
var
return, inputted, x : AnsiString;
i : integer;
begin inputted := copy(md5, 0, 32) + MD5;
for i := 1 to (length(md5) / 32) do
begin
x := copy(inputted, 33, 32)
return := return + readini('md5s', x, scriptpath + 'md5s.ini');
delete(inputted, 32, 32);
end;
return := replace(return, '&#8225;', ' ');
result := return;
end;

function HashEncrypt(Keyword, ToEncrypt : AnsiString) : AnsiString;
Var
Cyphered, md5ed : String;
i : integer;
begin
Cyphered := Cypher(Keyword, ToEncrypt);
For I := 1 to length(Cyphered) do
md5ed := md5ed + md5(strget(cyphered, I));
result := cypher(Keyword, md5ed);
end;

Function DeCypher(Codeword, ToDecrypt : string) : String;
var
return, C1, C2, Decrypting, Decrypted : string;
I : Integer;
begin
Return := CodeWord;
For I := 1 to length(Return) do
begin
if length(C1) < 25 then
begin
C1 := C1 + strget(Return, I);
end else
C2 := C2 + Strget(Return, I);
end;
C1 := Uppercase(C1);
C2 := Uppercase(C2);
For I := 40 to 90 do
begin
If length(C1) < 25 then
begin
If Pos(chr(I), C1) = 0 then
If Pos(chr(I), C2) = 0 then
C1 := C1 + chr(I);
end else
begin
If length(C2) < 25 then
begin
If Pos(chr(I), C1) = 0 then
If Pos(chr(I), C2) = 0 then
C2 := C2 + chr(I);
end;
end;
end;
Decrypting := uppercase(ToDecrypt);
For I := 1 to length(ToDecrypt) do
begin
If Pos(Strget(Decrypting, I), C1) <> 0 then
begin
Decrypted := Decrypted + Strget(C2, Pos(Strget(Decrypting, I), C1));
end else
begin
If Pos(Strget(Decrypting, I), C2) <> 0 then
begin
Decrypted := Decrypted + Strget(C1, Pos(Strget(Decrypting, I), C2));
end else
Decrypted := Decrypted + strget(Decrypting, I);
end;
end;
Result := Decrypted;
end;

function HashDecrypt(Keyword, ToDecrypt : AnsiString) : AnsiString;
Var
DeCyphered : String;
begin
DeCyphered := DeCypher(Keyword, ToDecrypt);
result := decypher(keyword, ReverseMD5(DeCyphered));
end;

begin
cleardebug;
writeln(Hashencrypt(codeword, encrypt));
writeln(hashdecrypt(codeword, Hashencrypt(codeword, encrypt)));
end.

The .ini file needed for this to work properly is this:

[md5s]
84c40473414caf2ed4a7b1283e48bbf4=(
9371d7a2e3ae86a00aab4771e39d255d=)
3389dae361af79b04c9c8e7057f60cc6=*
26b17225b626fb9238849fd60eabdf60=+
c0cb5f0fcf239ab3d9c1fcd31fff1efc=,
336d5ebc5436534e61d16e63ddfca327=-
5058f1af8388633f609cadb75a75dc9d=.
6666cd76f96956469e7be39d750cc7d9=/
cfcd208495d565ef66e7dff9f98764da=0
c4ca4238a0b923820dcc509a6f75849b=1
c81e728d9d4c2f636f067f89cc14862c=2
eccbc87e4b5ce2fe28308fd9f2a7baf3=3
a87ff679a2f3e71d9181a67b7542122c=4
e4da3b7fbbce2345d7772b0674a318d5=5
1679091c5a880faf6fb5e6087eb1b2dc=6
8f14e45fceea167a5a36dedd4bea2543=7
c9f0f895fb98ab9159f51fd0297e236d=8
45c48cce2e2d7fbdea1afc51c7c6ad26=9
853ae90f0351324bd73ea615e6487517=:
9eecb7db59d16c80417c72d1e1f4fbf1=;
524a50782178998021a88b8cd4c8dcd8=<
43ec3e5dee6e706af7766fffea512721==
cedf8da05466bb54708268b3c694a78f=>
d1457b72c3fb323a2671125aef3eab5d=?
518ed29525738cebdac49c49e60ea9d3=@
7fc56270e7a70fa81a5935b72eacbe29=A
9d5ed678fe57bcca610140957afab571=B
0d61f8370cad1d412f80b84d143e1257=C
f623e75af30e62bbd73d6df5b50bb7b5=D
3a3ea00cfc35332cedf6e5e9a32e94da=E
800618943025315f869e4e1f09471012=F
dfcf28d0734569a6a693bc8194de62bf=G
c1d9f50f86825a1a2302ec2449c17196=H
dd7536794b63bf90eccfd37f9b147d7f=I
ff44570aca8241914870afbc310cdb85=J
a5f3c6a11b03839d46af9fb43c97c188=K
d20caec3b48a1eef164cb4ca81ba2587=L
69691c7bdcc3ce6d5d8a1361f22d04ac=M
8d9c307cb7f3c4a32822a51922d1ceaa=N
f186217753c37b9b9f958d906208506e=O
44c29edb103a2872f519ad0c9a0fdaaa=P
f09564c9ca56850d4cd6b3319e541aee=Q
e1e1d3d40573127e9ee0480caf1283d6=R
5dbc98dcc983a70728bd082d1a47546e=S
b9ece18c950afbfa6b0fdbfa4ff731d3=T
4c614360da93c0a041b22e537de151eb=U
5206560a306a2e085a437fd258eb57ce=V
61e9c06ea9a85a5088a499df6458d276=W
02129bb861061d1a052c592e2dc6b383=X
57cec4137b614c87cb4e24a3d003a3e0=Y
21c2e59531c8710156d34a3c30ac81d5=Z
815417267f76f6f460a4a61f9db75fdb=[
28d397e87306b8631f3ed80d858d35f0=\
0fbd1776e1ad22c59a7080d35c7fd4db=]
7e6a2afe551e067a75fafacf47a6d981=^
b14a7b8059d9c055954c92674ce60032=_
833344d5e1432da82ef02e1301477ce8=`
0cc175b9c0f1b6a831c399e269772661=a
92eb5ffee6ae2fec3ad71c777531578f=b
4a8a08f09d37b73795649038408b5f33=c
8277e0910d750195b448797616e091ad=d
e1671797c52e15f763380b45e841ec32=e
8fa14cdd754f91cc6554c9e71929cce7=f
b2f5ff47436671b6e533d8dc3614845d=g
2510c39011c5be704182423e3a695e91=h
865c0c0b4ab0e063e5caa3387c1a8741=i
363b122c528f54df4a0446b6bab05515=j
8ce4b16b22b58894aa86c421e8759df3=k
2db95e8e1a9267b7a1188556b2013b33=l
6f8f57715090da2632453988d9a1501b=m
7b8b965ad4bca0e41ab51de7b31363a1=n
d95679752134a2d9eb61dbd7b91c4bcc=o
83878c91171338902e0fe0fb97a8c47a=p
7694f4a66316e53c8cdd9d9954bd611d=q
4b43b0aee35624cd95b910189b3dc231=r
03c7c0ace395d80182db07ae2c30f034=s
e358efa489f58062f10dd7316b65649e=t
7b774effe4a349c6dd82ad4f4f21d34c=u
9e3669d19b675bd57058fd4664205d2a=v
f1290186a5d0b1ceab27f4e77c0c5d68=w
9dd4e461268c8034f5c8564e155c67a6=x
7215ee9c7d9dc229d2921a40e899ec5f=&#8225;
9033e0e305f247c0c3c80d0c7848c8b3=!
b15835f133ff2e27c7cb28117bfae8f4="
01abfc750a0c942167651c40d088531d=#
c3e97dd6e97fb5125688c97f36720cbe=$
0bcef9c45bd8a48eda1b26eb0c61c869=%
6cff047854f19ac2aa52aac51bf3af4a=&
3590cb8af0bbb9e78c343b52b93773c9='
415290769594460e2e485922904f345d=y
fbade9e36a3f36d3d676c1b808451dd7=z

Place this somewhere in the folder you saved the script to, and then name it md5s.ini.

For example, if I use the keyword 'fred', and encrypt the string 'hello.', it gives me this:

*L*)Q=L=*=NOV()O@V*M=*@OM===M?=*@MPQT)TN*O=)ONO(NSTMMNQ(?=O?()Q@*=*@NLUPVQ@QSQ?=SS?T@==V=VUTSP@(*=*@NLUPVQ@QSQ?=SS?T@==V=VUTSP@(?**)*UT?P)Q*?N=?NUOLU=@V=N(T)(=O==PPQTL(*(UNPMVMPUTL(=)*OML*@)UQ


While the keyword 'freo' gives me this:

NNS+Q?)*QPNSQNP?SL+LS?SN++=*(NMT+LPQT)TM*N=)NMN(MSTLLMQ(?=N?()Q+*P*(PMNU(K)VMNUMK+**QKV(S=TQUPV)*P*(PMNU(K)VMNUMK+**QKV(S=TQUPV)QLU?+MVQMQTNU*?)+(*PV*PV?SK?(V+N++TQNSTVP)SN)=VK?**=+NT=V)LPT+T=

The decrypter (given the right keyword) will always return this:

HELLO.

Rate/Hate.

Suggestions welcome :).

~Sandstorm

XRaye

2009-10-02 01:00:38

Line 40: [Error] (40:25): Unknown identifier 'ToEncrypt' in script

Am I missing something?

Sandstorm

2009-10-02 01:02:55

Woops, small copy and paste error. Fixed, recopy it xD.

~Sandstorm

NxTitle

2009-10-02 01:41:37

Interesting concept, but why not shift the symbols around as well?

Sandstorm

2009-10-02 02:01:01

Haven't put those in yet :P.

Edit:

Added numbers and most symbols.

~Sandstorm

XRaye

2009-10-02 02:36:43

Hmm this is a neat idea :)

Infantry001

2009-10-02 05:11:00

Wow, really cool. There could be some really nice implementation with this!

Sandstorm

2009-10-02 05:29:11

Any suggestions on how it could be used, or how it could be improved?

It could probably be used for sending encrypted strings across the internet, but how often are people going to use it like that?

~Sandstorm

Awkwardsaw

2009-10-02 05:29:50

i gave you the idea in msn a few days ago! :p

also, why not use a matraci type of decoding and coding? it uses numbers and a pattern set by the person using it, so its literally decypherable unless you know the pattern, which is almost impossible :)

Sandstorm

2009-10-02 05:47:00

My challenge:

Write a script which will cycle through a given list of four letter words, and find the correct code word. My algorithm is found in the first post, as well as later in this one.

Here is a list of four letter words I'll be taking my code word from:

http://www.scrabble.org.au/words/fours.htm

Here is my Decoder, with the string to decode already placed in the "ToDecrypt" constant slot.

program Cypher_Decrypt;

var
C1, C2, Return, Decrypted, Decrypting : string;
I : Integer;

const
CodeWord = ':YO1)QKP@.ET;+<>8V,CRDF5*N4';
ToDecrypt = 'UE.Q9K.@.SQLU9.WH.@9+HW.UEK9P-E<';

begin
Return := CodeWord;
For I := 1 to length(Return) do
begin
if length(C1) < 25 then
begin
C1 := C1 + strget(Return, I);
end else
C2 := C2 + Strget(Return, I);
end;
C1 := Uppercase(C1);
C2 := Uppercase(C2);
For I := 40 to 90 do
begin
If length(C1) < 25 then
begin
If Pos(chr(I), C1) = 0 then
If Pos(chr(I), C2) = 0 then
C1 := C1 + chr(I);
end else
begin
If length(C2) < 25 then
begin
If Pos(chr(I), C1) = 0 then
If Pos(chr(I), C2) = 0 then
C2 := C2 + chr(I);
end;
end;
end;
Decrypting := uppercase(ToDecrypt);
For I := 1 to length(ToDecrypt) do
begin
If Pos(Strget(Decrypting, I), C1) <> 0 then
begin
Decrypted := Decrypted + Strget(C2, Pos(Strget(Decrypting, I), C1));
end else
begin
If Pos(Strget(Decrypting, I), C2) <> 0 then
begin
Decrypted := Decrypted + Strget(C1, Pos(Strget(Decrypting, I), C2));
end else
Decrypted := Decrypted + strget(Decrypting, I);
end;
end;
Cleardebug;
WriteLn(Decrypted);
end.

The output that will tell you your word is right is this:

The first person to post the sentence "Candles are awesome" wins.

~Sandstorm

Boreas

2009-10-02 06:47:40

Candles are awesome.

I win.

Sandstorm

2009-10-02 06:48:44

Lol, you win on the spiritual level. Now win on the physical one.

~Sandstorm

[-jesus-]

2009-10-02 06:55:55

Parsed to 1 word/combo per line for anyone else who is going to try. I gtg so i'll start tomorrow.
There's 5291:
http://drop.io/l8hmgjf

Sandstorm

2009-10-03 00:29:10

Changed the way it encrypts/decrypts now.

~Sandstorm