Skip to content
Extraits de code Groupes Projets
Valider 82129043 rédigé par Manon Dausort's avatar Manon Dausort
Parcourir les fichiers

Add new file

parent 13070a63
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
function encode(message::String)
num = zero(BigInt)
for byte in reverse(Vector{UInt8}(message))
num <<= 8
num |= byte
end
return num
end
function decode(num::BigInt)
message = UInt8[]
while !iszero(num)
push!(message, convert(UInt8, num & typemax(UInt8)))
num >>= 8
end
return String(message)
end
@assert decode(encode("Hello world")) == "Hello world"
decrypt(encrypted::BigInt, key::BigInt) = decode(encrypted - key)
encrypt(message::String, key::BigInt) = encode(message) + key
key = encode("key")
@assert decrypt(encrypt("Hello world", key), key) == "Hello world"
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter