Caesar cipher: Difference between revisions
Content deleted Content added
m syntax highlighting fixed |
→{{header|Ada}}: Fix the example, which was totally broken |
||
Line 383:
</pre>
=={{header|Ada}}==
<syntaxhighlight lang="ada">
with Ada.Text_IO; use Ada.Text_IO;
procedure Caesar is
-- Base function to encrypt a character
function Cipher(Char_To_Encrypt: Character; Shift: Integer; Base: Character) return Character is
begin
return
end
-- Function to encrypt a character
function Encrypt_Char(Char_To_Encrypt: Character; Shift:
begin
end Character;▼
-- Encrypt uppercase letters
return Cipher (Char_To_Encrypt, Shift, 'A');
-- Encrypt lowercase letters
return Cipher (Char_To_Encrypt, Shift, 'a');
-- Leave other characters unchanged
return Char_To_Encrypt;
end Encrypt_Char;
-- Function to decrypt a character
function Decrypt_Char(Char_To_Decrypt: Character; Shift: Integer) return Character is
begin
return Encrypt_Char(Char_To_Decrypt, -Shift);
for I in Playn'Range loop▼
end Decrypt_Char;
▲ case Playn(I) is
▲ when 'A' .. 'Z' =>
▲ when others =>
▲ end case;
end loop;▼
-- Shift value (can be any positive integer)
Encrypted_Message: String(Message'Range);
Decrypted_Message: String(Message'Range);
begin
-- Encrypt the message
Encrypted_Message(I) := Encrypt_Char(Message(I), Shift);
-- Decrypt the encrypted message
for I in Message'Range loop
Decrypted_Message(I) := Decrypt_Char(Encrypted_Message(I), Shift);
Ada.Text_IO.Put_Line("Ciphertext ----------->" & Text);▼
Ada.Text_IO.Put_Line("Decrypted Ciphertext ->" & crypt(Text, -Key));▼
-- Display results
end Caesar;</syntaxhighlight>▼
Put_Line("Plaintext: " & Message);
end Caesar;
{{out}}
<pre>> ./caesar
The five boxing wizards jump quickly
Plaintext:
Ciphertext:
Decrypted Ciphertext:
</pre>
=={{header|ALGOL 68}}==
{{trans|Ada|Note: This specimen retains the original [[#Ada|Ada]] coding style.}}
|