February 25, 2021, 02:12:57 AM

Author Topic: [bb] How encrypt a string by Filax [ 1+ years ago ]  (Read 614 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] How encrypt a string by Filax [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : How encrypt a string
Author : Filax
Posted : 1+ years ago

Description : Function for crypt a string with a key

Code :
Code: BlitzBasic
  1. Tmp$=FBK_CryptString$("This is a test",$E2CDF032)
  2. Print Tmp$
  4. Tmp2$=FBK_CryptString$(Tmp$,$E2CDF032)
  5. Print Tmp2$
  7. WaitKey
  9. Function FBK_CryptString$(Source$,Key)
  10.         For C=1 To Len(Source$)
  11.                 Char$=Char$+Chr$(Asc(Mid$(Source$,C,1) ) Xor Key)
  12.         Next
  14.         Return Char$
  15. End Function

Comments :

Rck(Posted 1+ years ago)

 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?

electronin(Posted 1+ years ago)

 Hey, Rck, you're right. Another thing I noticed, is any key starting with $ and ending with 32 will decrypt it. Any ideas, filax?

Koriolis(Posted 1+ years ago)

 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):
Code: [Select]
myKey$ = "yeepeekai"

Tmp$=FBK_CryptString$("This is a test",myKey)
Print Tmp$

Print Tmp2$


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) ))

Return Char$
End Function
The longer the key, the better it is.

Filax(Posted 1+ years ago)

 Thanks for this !! [/i]


SimplePortal 2.3.6 © 2008-2014, SimplePortal