Last active
September 13, 2017 12:20
-
-
Save hyhilman/622ac6d674b51c484cdf897f94d714d4 to your computer and use it in GitHub Desktop.
Caisar Cipher Text Matlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alfabet = "abcdefghijklmnopqrstuvwxyz" | |
alfabet = [alfabet, upper(alfabet), ' '] | |
plain = 'Aku makan es krim' | |
plainafterdecode = '' | |
key = 33 | |
cipher = '' | |
modulus = length(alfabet) | |
for plainsequence = 1:length(plain) | |
for alfabetsequence = 1:length(alfabet) | |
if plain(plainsequence) == alfabet(alfabetsequence) | |
i = mod(alfabetsequence + key - 1, modulus) + 1 | |
cipher = [cipher, alfabet(i)] | |
end | |
end | |
end | |
for ciphersequence = 1:length(cipher) | |
for alfabetsequence = 1:length(alfabet) | |
if cipher(ciphersequence) == alfabet(alfabetsequence) | |
i = mod(alfabetsequence - key - 1, modulus) + 1 | |
plainafterdecode = [plainafterdecode, alfabet(i)] | |
end | |
end | |
end | |
fprintf('%s -> %s -> %s \n', plain, cipher, plainafterdecode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment