XOR and Blowfish Xryption help!
BlitzMax Forums/BlitzMax Programming/XOR and Blowfish Xryption help!
| ||
Why doesn't this work? Text$ = "¤Top Secret 2[#]17 Mesage¤" '"fish" Password$ = "blowfish" Print "Data: "+Text Print "Key : "+Password EncryptString( Text, Password ) Print "After Encryption.. " Print "Data: "+Text Print "________________" EncryptString( Text, Password ) Print "After Decryption.. " Print "Data: "+Text Print "________________" Function EncryptString( Data$ Var, Key$ ) Local x,i,crypt$ For i = 0 Until Data.length 'Print Chr( Key[x])+" X: "+x'Chr( Data[i] ) Crypt:+ Chr( Data[i] ~ Key[x] ) x:+1 If x >= Key.length X=0 Next Data$ = Crypt$ EndFunctionIt works with a plain text key.. |
| ||
Can't remember how it works, but there are problems with XOR and certain characters :) |
| ||
You mean a bug? |
| ||
There's probably not a valid char for the result of some of your XORs - which is not necessarily a bug. |
| ||
Look this code archive, i hope this help you :) http://www.blitzbasic.com/codearcs/codearcs.php?code=822 |
| ||
Thank filax. But I can't make that one work either! Not if I blowfish as the key ;) Have nooo idea why. And if the data to encrypt is to "advanced" i.e. containing other characters than letters it's messed up to, just like mine. I'm not saying (yet) that the fault is in Blitzmax because I'm not very confortable with bit operations. If someone could explain the problem and perhaps solve it, that would be great!myKey$ = "T fish" myKey$ = "blowfish" Tmp$=FBK_CryptString$("Top Secret Message",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) ) ~ Asc(Mid$(Key$,1 + (C Mod lk),1) )) Next Return Char$ End Function |
| ||
Looks like this one works for me...Local pass$ = "blowfish" Local msg$ = "This is a secret message..."+Chr$(0)+Chr$(255)+" does it work?" Local crypt$ = xor_crypt(msg$,pass$) Print "Crypted: "+crypt$ Local decrypt$ = xor_crypt(crypt$,pass$) Print "Decrypted: "+decrypt$ Function xor_crypt:String( msg$, pass$ ) Local ml = Len(msg$) Local pl = Len(pass$) Local result$ For Local i = 0 Until ml Local c:Byte = msg$[i] Local k = pass$[ i Mod pl ] c = c ~ k result$:+Chr(c) Next Return result$ EndFunction As you can see I added some unprintable characters to the message and it decrypt it like it should. |
| ||
This is strange, deps, your example does not work for me?! It ends at the decrypt. Only the "Crypted: #"¤¤" is what is displayed, then Process complete. It does however work if I change the msg toa string without a space. Wierd is what it is.. What am I missing? Does the previous examples work for anyone else, is it just my computer? |
| ||
same problem here. |
| ||
Anyone? |
| ||
Funny, the example I wrote for bmax 1.10 doesn't work in 1.14... :P |
| ||
Looks like the bug/feature is inside print. This works for me: Edit: Yepp. print doesn't like ascii value 0 at all: Print Chr(0) Print "This is never going to be printed..." |
| ||
Now I get it! It works as long as you don't print a string with Chr(0), because then the program ends without error, lol. Thanks! |