—+++++++++++++++++++++++++++++++++++++++++++++++++
/opt/gcc-13.2.0-aarch64/bin/gnatmake
gcc -c -I./ -I- ./caesar.adb
caesar.adb:7:24: error: “modulo” is undefined
caesar.adb:7:30: error: missing “;”
caesar.adb:14:31: error: subprogram “modulo26” cannot be used before end of its declaration
caesar.adb:16:39: error: prefix of “Pos” attribute must be a type
caesar.adb:19:39: error: subprogram “modulo26” cannot be used before end of its declaration
caesar.adb:24:35: error: subprogram “modulo26” cannot be used before end of its declaration
caesar.adb:26:35: error: subprogram “modulo26” cannot be used before end of its declaration
caesar.adb:35:08: error: subprogram “modulo26” cannot be used before end of its declaration
gnatmake: “./caesar.adb” compilation error
Build failed.
—+++++++++++++++++++++++++++++++++++++++++++++++++
Is this a coding error in the Rosetta Code Task or is it that it worked in an earlier version of Ada or a different Ada compiler?
That’s a horror, not near to be valid Ada. It seems a joke or something machine-generated, but then, not very current. Bing copilot was able to generate this near valid implementation:
-- Caesar Cipher Implementation in Ada
with Ada.Text_IO;
use Ada.Text_IO;
procedure Caesar_Cipher is
-- Function to encrypt a character
function Encrypt_Char(Char_To_Encrypt: Character; Shift: Integer) return Character is
begin
if Char_To_Encrypt in 'A'..'Z' then
-- Only encrypt uppercase letters
return Character'Val((Character'Pos(Char_To_Encrypt) + Shift - Character'Pos('A')) mod 26 + Character'Pos('A'));
else
-- Leave other characters unchanged
return Char_To_Encrypt;
end if;
end Encrypt_Char;
-- Function to decrypt a character
function Decrypt_Char(Char_To_Decrypt: Character; Shift: Integer) return Character is
begin
if Char_To_Decrypt in 'A'..'Z' then
-- Only decrypt uppercase letters
return Character'Val((Character'Pos(Char_To_Decrypt) - Shift - Character'Pos('A')) mod 26 + Character'Pos('A'));
else
-- Leave other characters unchanged
return Char_To_Decrypt;
end if;
end Decrypt_Char;
-- Main procedure
procedure Main is
Message: String := "HELLO, WORLD!"; -- Example message
Shift: Integer := 3; -- Shift value (can be any positive integer)
Encrypted_Message: String(1..Message'Length);
Decrypted_Message: String(1..Message'Length);
begin
-- Encrypt the message
for I in Message'Range loop
Encrypted_Message(I) := Encrypt_Char(Message(I), Shift);
end loop;
-- Decrypt the encrypted message
for I in Message'Range loop
Decrypted_Message(I) := Decrypt_Char(Encrypted_Message(I), Shift);
end loop;
-- Display results
Put_Line("Original Message: " & Message);
Put_Line("Encrypted Message: " & Encrypted_Message);
Put_Line("Decrypted Message: " & Decrypted_Message);
end Main;
begin
null; -- Empty body
end Caesar_Cipher;
I only had to change null; to Main; to make it work.