This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lebalusch's profile picture

vigenére cipher script [solved]

Started by lebalusch, 29 June 2014 - 12:43 PM
lebalusch #1
Posted 29 June 2014 - 02:43 PM
So this is a vigenére cipher script i found on line.
Spoilerfunction Encrypt( _msg, _key )
local msg = { _msg:upper():byte( 1, -1 ) }
local key = { _key:upper():byte( 1, -1 ) }
local enc = {}

local j, k = 1, 1
for i = 1, #msg do
if msg[i] >= string.byte('A') and msg[i] <= string.byte('Z') then
enc[k] = ( msg[i] + key[j] - 2*string.byte('A') ) % 26 + string.byte('A')

k = k + 1
if j == #key then j = 1 else j = j + 1 end
end
end

return string.char( unpack(enc) )
end

function Decrypt( _msg, _key )
local msg = { _msg:byte( 1, -1 ) }
local key = { _key:upper():byte( 1, -1 ) }
local dec = {}

local j = 1
for i = 1, #msg do
dec[i] = ( msg[i] - key[j] + 26 ) % 26 + string.byte('A')

if j == #key then j = 1 else j = j + 1 end
end

return string.char( unpack(dec) )
end


original = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
key = "VIGENERECIPHER";

encrypted = Encrypt( original, key )
decrypted = Decrypt( encrypted, key )

print( encrypted )
print( decrypted )

The problems i have:
  • Cant use Numbers
  • Cant use Spaces (This That)
  • cant Use symbols (not to fussed about but would be nice too)
Thank you in advanced for viewing the post even if you have not been able to contribute a answer to help solve it. :)/>

EDIT:
Although the problem for the script has not been solved due to the cipher and its limitations itself a alternative was offered and found to be a better use for my needs. Finally switched to AES implementation.
Edited on 29 June 2014 - 02:25 PM
theoriginalbit #2
Posted 29 June 2014 - 02:51 PM
that's the point. the vigenere cipher wasn't intended for numbers, or symbols. and if you're planning on using it for data security don't, it is obfuscation at best, try encoding a string with 'zzzzzzz' it will come out the same, the vigenere cipher is flawed.
lebalusch #3
Posted 29 June 2014 - 03:37 PM
that's the point. the vigenere cipher wasn't intended for numbers, or symbols. and if you're planning on using it for data security don't, it is obfuscation at best, try encoding a string with 'zzzzzzz' it will come out the same, the vigenere cipher is flawed.

I have spent the last few days browsing these forums and cant really find anything that has working scripts for encrypting/ decrypting strings. All I really want is a plug and play script or api to pull apart and get working for some project.
theoriginalbit #4
Posted 29 June 2014 - 03:49 PM
well a vigenere cypher isn't an adequate replacement for encryption systems.

your 'days' of searching would have been severely reduced if you used the forums search feature. here are just 4 I found after using the search.
KillaVanillas AES
SquidDevs AES
NeverCasts RC4
AgentEs RC4

there's also every chance you may not need encryption (commonly people think to secure passwords you need encryption, hashing is adequate and normally better for this) there's also implementations of that on the forums, such as GravityScores SHA256 and KillaVanillas SHA256
lebalusch #5
Posted 29 June 2014 - 03:56 PM
Thanks for the reading and help, got some swotting to do now. Think read the killer one already. :-)
lebalusch #6
Posted 29 June 2014 - 04:22 PM
Decided on going for this one in the end the AES.
thank you for your help.
http://www.computercraft.info/forums2/index.php?/topic/18930-aes-encryption/