Was playing around trying to convert a sentence into a number (prolly impossible) but then just scrambling/unscrambling and stumbled upon this which doesn't make sense but works nonetheless.
Two Weird Things
1. How can you get a CHR of numbers > 255?? lol
2. How can you unscramble with a different code??
dim as string a,b,c,d="This can be any text"
for i as integer=1 to len(d)
b=mid(d,i,1)
b=chr(asc(b)+1000)
c+=b
next
d=""
?" scrambled= ";c
for i as integer=1 to len(c)
b=mid(c,i,1)
d+=chr(asc(b)-232)
next
?"unscrambled= ";d
sleep
ahh what's happening is that chr must wrap around after 255 ie. 256=0, 257=1 and so 512=0,768=0 and 1000-768=232 and that's why it works - not so magical as first thought :)
function Encrypt ( key as integer, chars as const string ) as string
Randomize( key )
var result = ""
for i as integer = 0 to Len( chars ) - 1
var x = Int( Rnd() * 255 )
result += Chr( chars[i] xor x ) ' chars[i] is the same as Asc(Mid(chars,i,1))
next i
return result
end function
var key = 5318008
var plaintext = "some plaintext stream"
var ciphertext = Encrypt( key, plaintext )
Print "encrypted: "; ciphertext
Print "decrypted: "; Encrypt( key, ciphertext )
Nice little program as it encrypts/decrypts although i have no idea how lol. I mean, the use of the key with randomize, and how it decrypts when it appears to be all random haha.
Will have to study it, and check out the links too which might give me an idea :)
I initially wanted to create an integer of the string ie. a short number like 37684 that would represent the string, but that may be impossible or at the very least above my programming capabilities. Anyhow encrypting is interesting for the fact it hides stuff :)
Hi. Randomize is used to seed the random number generator; a different seed will tell Rnd to produce a different sequence of random numbers. But if you use the same seed (our key), Rnd will produce the same sequence.
When you have time, look into hash functions; they take a stream of characters and turn them into a number. They're useful for creating data structures that are very fast and efficient to add and search for elements, like associative arrays or hash tables; the number generated is used as an index into an array.
Some kinds of hash functions are used to verify the integrity of some data (like when you download a file) since they give relatively strong guarantees that if the data is corrupted or tampered with, the number generated from it will be different than the one generated from the original.
But hash functions in general won't allow you to "decode" the number back into the original string, so you might have to research other topics (like maybe compression).
Cool, glad you got some new things to think about. :)
One of my favorite NES games uses a cipher like the ones we've posted to encrypt the passwords it gives you when you save the game. It was lots of fun to mess around with the debugger and figure out how the game was doing that, I even wrote a FB program so I could create my own passwords and start the game with the gold/items I wanted! :)