Code archives/File Utilities/How encrypt a string
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Function for crypt a string with a key | |||||
Tmp$=FBK_CryptString$("This is a test",$E2CDF032) Print Tmp$ Tmp2$=FBK_CryptString$(Tmp$,$E2CDF032) Print Tmp2$ WaitKey Function FBK_CryptString$(Source$,Key) For C=1 To Len(Source$) Char$=Char$+Chr$(Asc(Mid$(Source$,C,1) ) Xor Key) Next Return Char$ End Function |
Comments
| ||
it seems that when i change the decrpyt key to $32 it still decrypts the key... not so safe? Also, some change can be made to the encrypt key and will still be decryptable with $32.. can you explain why this works? |
| ||
Hey, Rck, you're right. Another thing I noticed, is any key starting with $ and ending with 32 will decrypt it. Any ideas, filax? |
| ||
The problem is than only the lower byte is used in this scheme. So the key here is in fact $32, whatever the other bytes are. Xoring is a very basic way of encrypting, it's very far from safe, but is probably good enough to prevent most people to rip your medias. But at the very least it would be good to have a longer key. Not that it's a lot safer (still very weak) but as it's as easy and fast to do, why not? Something like this (no optimization): myKey$ = "yeepeekai" Tmp$=FBK_CryptString$("This is a test",myKey) Print Tmp$ Tmp2$=FBK_CryptString$(Tmp$,myKey) Print Tmp2$ WaitKey Function FBK_CryptString$(Source$,Key$) Local ls = Len(Source$) Local lk = Len(Key) For C=1 To ls Char$=Char$+Chr$(Asc(Mid$(Source$,C,1) ) Xor Asc(Mid$(Key$,1 + (C Mod lk),1) )) Next Return Char$ End Function The longer the key, the better it is. |
| ||
Thanks for this !! |
Code Archives Forum