WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sorting algorithms_Sleep sort


C++: #include <chrono>
#include <iostream>
#include <thread>
#include <vector>

int main(int argc, char* argv[]) {
  std::vector<std::thread> threads;

  for (int i = 1; i < argc; ++i) {
    threads.emplace_back([i, &argv]() {
      int arg = std::stoi(argv[i]);
      std::this_thread::sleep_for(std::chrono::seconds(arg));
      std::cout << argv[i] << std::endl;
    });
  }

  for (auto& thread : threads) {
    thread.join();
  }
}









Fortran: program sleepSort
    use omp_lib
    implicit none
    integer::nArgs,myid,i,stat
    integer,allocatable::intArg(:)
    character(len=5)::arg

    
    nArgs=command_argument_count()
    if(nArgs==0)stop ' : No argument is given 
    allocate(intArg(nArgs))
    do i=1,nArgs
        call get_command_argument(i, arg)
	read(arg,'(I5)',iostat=stat)intArg(i)
	if(intArg(i)<0 .or. stat/=0) stop&
        &' :Only 0 or positive integer allowed 
    end do
    call omp_set_num_threads(nArgs)
    
 

    
    myid =omp_get_thread_num()
    call sleepNprint(intArg(myid+1))
    

  contains
	subroutine sleepNprint(nSeconds)
	    integer::nSeconds
            call sleep(nSeconds)
	    print*,nSeconds
	end subroutine sleepNprint
end program sleepSort
Task: Sorting algorithms_Sleep sort

C: >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]










Fortran: program sleepSort
    use omp_lib
    implicit none
    integer::nArgs,myid,i,stat
    integer,allocatable::intArg(:)
    character(len=5)::arg

    
    nArgs=command_argument_count()
    if(nArgs==0)stop ' : No argument is given 
    allocate(intArg(nArgs))
    do i=1,nArgs
        call get_command_argument(i, arg)
	read(arg,'(I5)',iostat=stat)intArg(i)
	if(intArg(i)<0 .or. stat/=0) stop&
        &' :Only 0 or positive integer allowed 
    end do
    call omp_set_num_threads(nArgs)
    
 

    
    myid =omp_get_thread_num()
    call sleepNprint(intArg(myid+1))
    

  contains
	subroutine sleepNprint(nSeconds)
	    integer::nSeconds
            call sleep(nSeconds)
	    print*,nSeconds
	end subroutine sleepNprint
end program sleepSort
Task: Sorting algorithms_Sleep sort





Java: import java.util.concurrent.CountDownLatch;

public class SleepSort {
	public static void sleepSortAndPrint(int[] nums) {
		final CountDownLatch doneSignal = new CountDownLatch(nums.length);
		for (final int num : nums) {
			new Thread(new Runnable() {
				public void run() {
					doneSignal.countDown();
					try {
						doneSignal.await();

						
						
						
						Thread.sleep(num * 1000);
						System.out.println(num);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}).start();
		}
	}
	public static void main(String[] args) {
		int[] nums = new int[args.length];
		for (int i = 0; i < args.length; i++)
			nums[i] = Integer.parseInt(args[i]);
		sleepSortAndPrint(nums);
	}
}






Fortran: program sleepSort
    use omp_lib
    implicit none
    integer::nArgs,myid,i,stat
    integer,allocatable::intArg(:)
    character(len=5)::arg

    
    nArgs=command_argument_count()
    if(nArgs==0)stop ' : No argument is given 
    allocate(intArg(nArgs))
    do i=1,nArgs
        call get_command_argument(i, arg)
	read(arg,'(I5)',iostat=stat)intArg(i)
	if(intArg(i)<0 .or. stat/=0) stop&
        &' :Only 0 or positive integer allowed 
    end do
    call omp_set_num_threads(nArgs)
    
 

    
    myid =omp_get_thread_num()
    call sleepNprint(intArg(myid+1))
    

  contains
	subroutine sleepNprint(nSeconds)
	    integer::nSeconds
            call sleep(nSeconds)
	    print*,nSeconds
	end subroutine sleepNprint
end program sleepSort
Task: Sorting algorithms_Sleep sort







Python: from time import sleep
from threading import Timer

def sleepsort(values):
    sleepsort.result = []
    def add1(x):
        sleepsort.result.append(x)
    mx = values[0]
    for v in values:
        if mx < v: mx = v
        Timer(v, add1, [v]).start()
    sleep(mx+1)
    return sleepsort.result

if __name__ == '__main__':
    x = [3,2,4,7,3,6,9,1]
    if sleepsort(x) == sorted(x):
        print('sleep sort worked for:',x)
    else:
        print('sleep sort FAILED for:',x)




Fortran: program sleepSort
    use omp_lib
    implicit none
    integer::nArgs,myid,i,stat
    integer,allocatable::intArg(:)
    character(len=5)::arg

    
    nArgs=command_argument_count()
    if(nArgs==0)stop ' : No argument is given 
    allocate(intArg(nArgs))
    do i=1,nArgs
        call get_command_argument(i, arg)
	read(arg,'(I5)',iostat=stat)intArg(i)
	if(intArg(i)<0 .or. stat/=0) stop&
        &' :Only 0 or positive integer allowed 
    end do
    call omp_set_num_threads(nArgs)
    
 

    
    myid =omp_get_thread_num()
    call sleepNprint(intArg(myid+1))
    

  contains
	subroutine sleepNprint(nSeconds)
	    integer::nSeconds
            call sleep(nSeconds)
	    print*,nSeconds
	end subroutine sleepNprint
end program sleepSort
Task: Sorting algorithms_Sleep sort








VB: Imports System.Threading

Module Module1

    Sub SleepSort(items As IEnumerable(Of Integer))
        For Each item In items
            Task.Factory.StartNew(Sub()
                                      Thread.Sleep(1000 * item)
                                      Console.WriteLine(item)
                                  End Sub)
        Next
    End Sub

    Sub Main()
        SleepSort({1, 5, 2, 1, 8, 10, 3})
        Console.ReadKey()
    End Sub

End Module



Fortran: program sleepSort
    use omp_lib
    implicit none
    integer::nArgs,myid,i,stat
    integer,allocatable::intArg(:)
    character(len=5)::arg

    
    nArgs=command_argument_count()
    if(nArgs==0)stop ' : No argument is given 
    allocate(intArg(nArgs))
    do i=1,nArgs
        call get_command_argument(i, arg)
	read(arg,'(I5)',iostat=stat)intArg(i)
	if(intArg(i)<0 .or. stat/=0) stop&
        &' :Only 0 or positive integer allowed 
    end do
    call omp_set_num_threads(nArgs)
    
 

    
    myid =omp_get_thread_num()
    call sleepNprint(intArg(myid+1))
    

  contains
	subroutine sleepNprint(nSeconds)
	    integer::nSeconds
            call sleep(nSeconds)
	    print*,nSeconds
	end subroutine sleepNprint
end program sleepSort
Task: Sorting algorithms_Sleep sort






PHP: <?php

$buffer = 1;
$pids = [];

for ($i = 1; $i < $argc; $i++) {
    $pid = pcntl_fork();
    if ($pid < 0) {
        die("failed to start child process");
    }

    if ($pid === 0) {
        sleep($argv[$i] + $buffer);
        echo $argv[$i] . "\n";
        exit();
    }
    
    $pids[] = $pid;
}

foreach ($pids as $pid) {
    pcntl_waitpid($pid, $status);
}





Fortran: program sleepSort
    use omp_lib
    implicit none
    integer::nArgs,myid,i,stat
    integer,allocatable::intArg(:)
    character(len=5)::arg

    
    nArgs=command_argument_count()
    if(nArgs==0)stop ' : No argument is given 
    allocate(intArg(nArgs))
    do i=1,nArgs
        call get_command_argument(i, arg)
	read(arg,'(I5)',iostat=stat)intArg(i)
	if(intArg(i)<0 .or. stat/=0) stop&
        &' :Only 0 or positive integer allowed 
    end do
    call omp_set_num_threads(nArgs)
    
 

    
    myid =omp_get_thread_num()
    call sleepNprint(intArg(myid+1))
    

  contains
	subroutine sleepNprint(nSeconds)
	    integer::nSeconds
            call sleep(nSeconds)
	    print*,nSeconds
	end subroutine sleepNprint
end program sleepSort
Task: Sorting algorithms_Sleep sort






PHP: <?php

$buffer = 1;
$pids = [];

for ($i = 1; $i < $argc; $i++) {
    $pid = pcntl_fork();
    if ($pid < 0) {
        die("failed to start child process");
    }

    if ($pid === 0) {
        sleep($argv[$i] + $buffer);
        echo $argv[$i] . "\n";
        exit();
    }
    
    $pids[] = $pid;
}

foreach ($pids as $pid) {
    pcntl_waitpid($pid, $status);
}
Task: Sorting algorithms_Sleep sort






PHP: <?php

$buffer = 1;
$pids = [];

for ($i = 1; $i < $argc; $i++) {
    $pid = pcntl_fork();
    if ($pid < 0) {
        die("failed to start child process");
    }

    if ($pid === 0) {
        sleep($argv[$i] + $buffer);
        echo $argv[$i] . "\n";
        exit();
    }
    
    $pids[] = $pid;
}

foreach ($pids as $pid) {
    pcntl_waitpid($pid, $status);
}






Ada: with Ada.Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
procedure SleepSort is
   task type PrintTask (num : Integer);
   task body PrintTask is begin
      delay Duration (num) / 100.0;
      Ada.Text_IO.Put(num'Img);
   end PrintTask;
   type TaskAcc is access PrintTask;
   TaskList : array (1 .. Argument_Count) of TaskAcc;
begin
   for i in TaskList'Range loop
      TaskList(i) := new PrintTask(Integer'Value(Argument(i)));
   end loop;
end SleepSort;
Task: Random number generator (device)



C#: using System;
using System.Security.Cryptography;

private static int GetRandomInt()
{
  int result = 0;
  var rng = new RNGCryptoServiceProvider();
  var buffer = new byte[4];

  rng.GetBytes(buffer);
  result = BitConverter.ToInt32(buffer, 0);

  return result;
}









Ada: with Ada.Streams.Stream_IO;
with Ada.Text_IO;
procedure Random is
   Number : Integer;
   Random_File : Ada.Streams.Stream_IO.File_Type;
begin
   Ada.Streams.Stream_IO.Open (File => Random_File,
                               Mode => Ada.Streams.Stream_IO.In_File,
                               Name => "/dev/random");
   Integer'Read (Ada.Streams.Stream_IO.Stream (Random_File), Number);
   Ada.Streams.Stream_IO.Close (Random_File);
   Ada.Text_IO.Put_Line ("Number:" & Integer'Image (Number));
end Random;
Task: Random number generator (device)

C: #include <stdio.h>
#include <stdlib.h>

#define RANDOM_PATH "/dev/urandom"

int main(void)
{
        unsigned char buf[4];
        unsigned long v;
        FILE *fin;

        if ((fin = fopen(RANDOM_PATH, "r")) == NULL) {
                fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH);
                return EXIT_FAILURE;
        }
        if (fread(buf, 1, sizeof buf, fin) != sizeof buf) {
                fprintf(stderr, "%s: not enough bytes (expected %u)\n",
                        RANDOM_PATH, (unsigned) sizeof buf);
                return EXIT_FAILURE;
        }
        fclose(fin);
        v = buf[0] | buf[1] << 8UL | buf[2] << 16UL | buf[3] << 24UL;
        printf("%lu\n", v);
        return 0;
}











Ada: with Ada.Streams.Stream_IO;
with Ada.Text_IO;
procedure Random is
   Number : Integer;
   Random_File : Ada.Streams.Stream_IO.File_Type;
begin
   Ada.Streams.Stream_IO.Open (File => Random_File,
                               Mode => Ada.Streams.Stream_IO.In_File,
                               Name => "/dev/random");
   Integer'Read (Ada.Streams.Stream_IO.Stream (Random_File), Number);
   Ada.Streams.Stream_IO.Close (Random_File);
   Ada.Text_IO.Put_Line ("Number:" & Integer'Image (Number));
end Random;
Task: Random number generator (device)


C++: #include <iostream>
#include <random>
 
int main()
{
    std::random_device rd;
    std::uniform_int_distribution<long> dist; 
    
    std::cout << "Random Number: " << dist(rd) << std::endl;
}










Ada: with Ada.Streams.Stream_IO;
with Ada.Text_IO;
procedure Random is
   Number : Integer;
   Random_File : Ada.Streams.Stream_IO.File_Type;
begin
   Ada.Streams.Stream_IO.Open (File => Random_File,
                               Mode => Ada.Streams.Stream_IO.In_File,
                               Name => "/dev/random");
   Integer'Read (Ada.Streams.Stream_IO.Stream (Random_File), Number);
   Ada.Streams.Stream_IO.Close (Random_File);
   Ada.Text_IO.Put_Line ("Number:" & Integer'Image (Number));
end Random;
Task: Random number generator (device)




Go: package main

import (
    "crypto/rand"
    "encoding/binary"
    "fmt"
    "io"
    "os"
)

func main() {
    testRandom("crypto/rand", rand.Reader)
    testRandom("dev/random", newDevRandom())
}

func newDevRandom() (f *os.File) {
    var err error
    if f, err = os.Open("/dev/random"); err != nil {
        panic(err)
    }
    return
}

func testRandom(label string, src io.Reader) {
    fmt.Printf("%s:\n", label)
    var r int32
    for i := 0; i < 10; i++ {
        if err := binary.Read(src, binary.LittleEndian, &r); err != nil {
            panic(err)
        }
        fmt.Print(r, " ")
    }
    fmt.Println()
}








Ada: with Ada.Streams.Stream_IO;
with Ada.Text_IO;
procedure Random is
   Number : Integer;
   Random_File : Ada.Streams.Stream_IO.File_Type;
begin
   Ada.Streams.Stream_IO.Open (File => Random_File,
                               Mode => Ada.Streams.Stream_IO.In_File,
                               Name => "/dev/random");
   Integer'Read (Ada.Streams.Stream_IO.Stream (Random_File), Number);
   Ada.Streams.Stream_IO.Close (Random_File);
   Ada.Text_IO.Put_Line ("Number:" & Integer'Image (Number));
end Random;
Task: Random number generator (device)





Java: import java.security.SecureRandom;

public class RandomExample {
  public static void main(String[] args) {
    SecureRandom rng = new SecureRandom();

    
    System.out.println(rng.nextInt());
  }
}







Ada: with Ada.Streams.Stream_IO;
with Ada.Text_IO;
procedure Random is
   Number : Integer;
   Random_File : Ada.Streams.Stream_IO.File_Type;
begin
   Ada.Streams.Stream_IO.Open (File => Random_File,
                               Mode => Ada.Streams.Stream_IO.In_File,
                               Name => "/dev/random");
   Integer'Read (Ada.Streams.Stream_IO.Stream (Random_File), Number);
   Ada.Streams.Stream_IO.Close (Random_File);
   Ada.Text_IO.Put_Line ("Number:" & Integer'Image (Number));
end Random;
Task: Random number generator (device)







Python: import random
rand = random.SystemRandom()
rand.randint(1,10)





Ada: with Ada.Streams.Stream_IO;
with Ada.Text_IO;
procedure Random is
   Number : Integer;
   Random_File : Ada.Streams.Stream_IO.File_Type;
begin
   Ada.Streams.Stream_IO.Open (File => Random_File,
                               Mode => Ada.Streams.Stream_IO.In_File,
                               Name => "/dev/random");
   Integer'Read (Ada.Streams.Stream_IO.Stream (Random_File), Number);
   Ada.Streams.Stream_IO.Close (Random_File);
   Ada.Text_IO.Put_Line ("Number:" & Integer'Image (Number));
end Random;
Task: Random number generator (device)

C: #include <stdio.h>
#include <stdlib.h>

#define RANDOM_PATH "/dev/urandom"

int main(void)
{
        unsigned char buf[4];
        unsigned long v;
        FILE *fin;

        if ((fin = fopen(RANDOM_PATH, "r")) == NULL) {
                fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH);
                return EXIT_FAILURE;
        }
        if (fread(buf, 1, sizeof buf, fin) != sizeof buf) {
                fprintf(stderr, "%s: not enough bytes (expected %u)\n",
                        RANDOM_PATH, (unsigned) sizeof buf);
                return EXIT_FAILURE;
        }
        fclose(fin);
        v = buf[0] | buf[1] << 8UL | buf[2] << 16UL | buf[3] << 24UL;
        printf("%lu\n", v);
        return 0;
}
Task: Random number generator (device)



C#: using System;
using System.Security.Cryptography;

private static int GetRandomInt()
{
  int result = 0;
  var rng = new RNGCryptoServiceProvider();
  var buffer = new byte[4];

  rng.GetBytes(buffer);
  result = BitConverter.ToInt32(buffer, 0);

  return result;
}
Task: Random number generator (device)


C++: #include <iostream>
#include <random>
 
int main()
{
    std::random_device rd;
    std::uniform_int_distribution<long> dist; 
    
    std::cout << "Random Number: " << dist(rd) << std::endl;
}
Task: Random number generator (device)





Java: import java.security.SecureRandom;

public class RandomExample {
  public static void main(String[] args) {
    SecureRandom rng = new SecureRandom();

    
    System.out.println(rng.nextInt());
  }
}
Task: Random number generator (device)







Python: import random
rand = random.SystemRandom()
rand.randint(1,10)
Task: Random number generator (device)




Go: package main

import (
    "crypto/rand"
    "encoding/binary"
    "fmt"
    "io"
    "os"
)

func main() {
    testRandom("crypto/rand", rand.Reader)
    testRandom("dev/random", newDevRandom())
}

func newDevRandom() (f *os.File) {
    var err error
    if f, err = os.Open("/dev/random"); err != nil {
        panic(err)
    }
    return
}

func testRandom(label string, src io.Reader) {
    fmt.Printf("%s:\n", label)
    var r int32
    for i := 0; i < 10; i++ {
        if err := binary.Read(src, binary.LittleEndian, &r); err != nil {
            panic(err)
        }
        fmt.Print(r, " ")
    }
    fmt.Println()
}
Task: Random number generator (device)



C#: using System;
using System.Security.Cryptography;

private static int GetRandomInt()
{
  int result = 0;
  var rng = new RNGCryptoServiceProvider();
  var buffer = new byte[4];

  rng.GetBytes(buffer);
  result = BitConverter.ToInt32(buffer, 0);

  return result;
}








Fortran: 


program    urandom_test
  use iso_c_binding, only : c_long
  implicit none

  character(len=*), parameter :: RANDOM_PATH = "/dev/urandom"
  integer :: funit, ios
  integer(c_long) :: buf

  open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", &
       iostat=ios, status="old", action="read")
  if ( ios /= 0 ) stop "Error opening file: "//RANDOM_PATH

  read(funit) buf

  close(funit)

  write(*,'(A,I64)') "Integer:     ", buf
  write(*,'(A,B64)') "Binary:      ", buf
  write(*,'(A,Z64)') "Hexadecimal: ", buf

end program urandom_test
Task: Random number generator (device)


C++: #include <iostream>
#include <random>
 
int main()
{
    std::random_device rd;
    std::uniform_int_distribution<long> dist; 
    
    std::cout << "Random Number: " << dist(rd) << std::endl;
}









Fortran: 


program    urandom_test
  use iso_c_binding, only : c_long
  implicit none

  character(len=*), parameter :: RANDOM_PATH = "/dev/urandom"
  integer :: funit, ios
  integer(c_long) :: buf

  open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", &
       iostat=ios, status="old", action="read")
  if ( ios /= 0 ) stop "Error opening file: "//RANDOM_PATH

  read(funit) buf

  close(funit)

  write(*,'(A,I64)') "Integer:     ", buf
  write(*,'(A,B64)') "Binary:      ", buf
  write(*,'(A,Z64)') "Hexadecimal: ", buf

end program urandom_test
Task: Random number generator (device)

C: #include <stdio.h>
#include <stdlib.h>

#define RANDOM_PATH "/dev/urandom"

int main(void)
{
        unsigned char buf[4];
        unsigned long v;
        FILE *fin;

        if ((fin = fopen(RANDOM_PATH, "r")) == NULL) {
                fprintf(stderr, "%s: unable to open file\n", RANDOM_PATH);
                return EXIT_FAILURE;
        }
        if (fread(buf, 1, sizeof buf, fin) != sizeof buf) {
                fprintf(stderr, "%s: not enough bytes (expected %u)\n",
                        RANDOM_PATH, (unsigned) sizeof buf);
                return EXIT_FAILURE;
        }
        fclose(fin);
        v = buf[0] | buf[1] << 8UL | buf[2] << 16UL | buf[3] << 24UL;
        printf("%lu\n", v);
        return 0;
}










Fortran: 


program    urandom_test
  use iso_c_binding, only : c_long
  implicit none

  character(len=*), parameter :: RANDOM_PATH = "/dev/urandom"
  integer :: funit, ios
  integer(c_long) :: buf

  open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", &
       iostat=ios, status="old", action="read")
  if ( ios /= 0 ) stop "Error opening file: "//RANDOM_PATH

  read(funit) buf

  close(funit)

  write(*,'(A,I64)') "Integer:     ", buf
  write(*,'(A,B64)') "Binary:      ", buf
  write(*,'(A,Z64)') "Hexadecimal: ", buf

end program urandom_test
Task: Random number generator (device)





Java: import java.security.SecureRandom;

public class RandomExample {
  public static void main(String[] args) {
    SecureRandom rng = new SecureRandom();

    
    System.out.println(rng.nextInt());
  }
}






Fortran: 


program    urandom_test
  use iso_c_binding, only : c_long
  implicit none

  character(len=*), parameter :: RANDOM_PATH = "/dev/urandom"
  integer :: funit, ios
  integer(c_long) :: buf

  open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", &
       iostat=ios, status="old", action="read")
  if ( ios /= 0 ) stop "Error opening file: "//RANDOM_PATH

  read(funit) buf

  close(funit)

  write(*,'(A,I64)') "Integer:     ", buf
  write(*,'(A,B64)') "Binary:      ", buf
  write(*,'(A,Z64)') "Hexadecimal: ", buf

end program urandom_test
Task: Random number generator (device)







Python: import random
rand = random.SystemRandom()
rand.randint(1,10)




Fortran: 


program    urandom_test
  use iso_c_binding, only : c_long
  implicit none

  character(len=*), parameter :: RANDOM_PATH = "/dev/urandom"
  integer :: funit, ios
  integer(c_long) :: buf

  open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", &
       iostat=ios, status="old", action="read")
  if ( ios /= 0 ) stop "Error opening file: "//RANDOM_PATH

  read(funit) buf

  close(funit)

  write(*,'(A,I64)') "Integer:     ", buf
  write(*,'(A,B64)') "Binary:      ", buf
  write(*,'(A,Z64)') "Hexadecimal: ", buf

end program urandom_test
Task: RSA code



C#: using System;
using System.Numerics;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        BigInteger n = BigInteger.Parse("9516311845790656153499716760847001433441357");
        BigInteger e = 65537;
        BigInteger d = BigInteger.Parse("5617843187844953170308463622230283376298685");

        const string plaintextstring = "Hello, Rosetta!";
        byte[] plaintext = ASCIIEncoding.ASCII.GetBytes(plaintextstring);
        BigInteger pt = new BigInteger(plaintext);
        if (pt > n)
            throw new Exception();

        BigInteger ct = BigInteger.ModPow(pt, e, n);
        Console.WriteLine("Encoded:  " + ct);

        BigInteger dc = BigInteger.ModPow(ct, d, n);
        Console.WriteLine("Decoded:  " + dc);

        string decoded = ASCIIEncoding.ASCII.GetString(dc.ToByteArray());
        Console.WriteLine("As ASCII: " + decoded);
    }
}









Ada: 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;

   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;