Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,38 +0,0 @@
|
|||
WITH GMP, GMP.Integers, Ada.Text_IO, GMP.Integers.Aliased_Internal_Value, Interfaces.C;
|
||||
USE GMP, Gmp.Integers, Ada.Text_IO, Interfaces.C;
|
||||
|
||||
PROCEDURE Main IS
|
||||
FUNCTION "+" (U : Unbounded_Integer) RETURN Mpz_T IS (Aliased_Internal_Value (U));
|
||||
FUNCTION "+" (S : String) RETURN Unbounded_Integer IS (To_Unbounded_Integer (S));
|
||||
FUNCTION Image_Cleared (M : Mpz_T) RETURN String IS (Image (To_Unbounded_Integer (M)));
|
||||
N : Unbounded_Integer := +"9516311845790656153499716760847001433441357";
|
||||
E : Unbounded_Integer := +"65537";
|
||||
D : Unbounded_Integer := +"5617843187844953170308463622230283376298685";
|
||||
Plain_Text : CONSTANT String := "Rosetta Code";
|
||||
M, M_C, M_D : Mpz_T;
|
||||
-- We import two C functions from the GMP library which are not in the specs of the gmp package
|
||||
PROCEDURE Mpz_Import
|
||||
(Rop : Mpz_T; Count : Size_T; Order : Int; Size : Size_T; Endian : Int;
|
||||
Nails : Size_T; Op : Char_Array);
|
||||
PRAGMA Import (C, Mpz_Import, "__gmpz_import");
|
||||
|
||||
PROCEDURE Mpz_Export
|
||||
(Rop : OUT Char_Array; Count : ACCESS Size_T; Order : Int; Size : Size_T;
|
||||
Endian : Int; Nails : Size_T; Op : Mpz_T);
|
||||
PRAGMA Import (C, Mpz_Export, "__gmpz_export");
|
||||
BEGIN
|
||||
Mpz_Init (M);
|
||||
Mpz_Init (M_C);
|
||||
Mpz_Init (M_D);
|
||||
Mpz_Import (M, Plain_Text'Length + 1, 1, 1, 0, 0, To_C (Plain_Text));
|
||||
Mpz_Powm (M_C, M, +E, +N);
|
||||
Mpz_Powm (M_D, M_C, +D, +N);
|
||||
Put_Line ("Encoded plain text: " & Image_Cleared (M));
|
||||
DECLARE Decrypted : Char_Array (1 .. Mpz_Sizeinbase (M_C, 256));
|
||||
BEGIN
|
||||
Put_Line ("Encryption of this encoding: " & Image_Cleared (M_C));
|
||||
Mpz_Export (Decrypted, NULL, 1, 1, 0, 0, M_D);
|
||||
Put_Line ("Decryption of the encoding: " & Image_Cleared (M_D));
|
||||
Put_Line ("Final decryption: " & To_Ada (Decrypted));
|
||||
END;
|
||||
END Main;
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
$n = [BigInt]::Parse("9516311845790656153499716760847001433441357")
|
||||
$e = [BigInt]::new(65537)
|
||||
$d = [BigInt]::Parse("5617843187844953170308463622230283376298685")
|
||||
$plaintextstring = "Hello, Rosetta!"
|
||||
$plaintext = [Text.ASCIIEncoding]::ASCII.GetBytes($plaintextstring)
|
||||
[BigInt]$pt = [BigInt]::new($plaintext)
|
||||
if ($n -lt $pt) {throw "`$n = $n < $pt = `$pt"}
|
||||
$ct = [BigInt]::ModPow($pt, $e, $n)
|
||||
"Encoded: $ct"
|
||||
$dc = [BigInt]::ModPow($ct, $d, $n)
|
||||
"Decoded: $dc"
|
||||
$decoded = [Text.ASCIIEncoding]::ASCII.GetString($dc.ToByteArray())
|
||||
"As ASCII: $decoded"
|
||||
Loading…
Add table
Add a link
Reference in a new issue