godot ceasar cipher
now even you can hide your military plans in plain sight
class_name CeasarCipher
extends Node
const ALPHABET: Array = ["a","b",'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
func _ready():
print(encrypt("Hello! My name is George. Don't say my name wrongly! Why would you do that??? I hope if you do, it will be a very valuable lesson... !@#$%^&*()_+"))
print(decrypt("khoor! pb qdph lv jhrujh. grq'w vdb pb qdph zurqjob! zkb zrxog brx gr wkdw??? l krsh li brx gr, lw zloo eh d yhub ydoxdeoh ohvvrq... !@#$%^&*()_+"))
func encrypt(string: String, displacement_amount: int = 3) -> String:
var encrypted_string: String = ""
for i in string.length():
for e in ALPHABET.size():
if string[i].to_lower() == ALPHABET[e].to_lower():
encrypted_string += ALPHABET[(e + displacement_amount) % 26]
break
if !string[i].to_lower() in ALPHABET:
encrypted_string += string[i]
return encrypted_string
func decrypt(string: String, displacement_amount: int = 3) -> String:
var decrypted_string: String = ""
for i in string.length():
for e in ALPHABET.size():
if string[i].to_lower() == ALPHABET[e].to_lower():
decrypted_string += ALPHABET[(e - displacement_amount + 26) % 26]
break
if !string[i].to_lower() in ALPHABET:
decrypted_string += string[i]
return decrypted_string
#godot #gdscript #indiedev #cryptography