Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Convert the following code from Lua to VB, ensuring the logic remains intact.
local function encrypt(text, key) return text:gsub("%a", function(t) local base = (t:lower() == t and string.byte('a') or string.byte('A')) local r = t:byte() - base r = r + key r = r%26 r = r + base return string.char(r) end) end local function decrypt(text, key) return encrypt(text, -key) end...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Write a version of this Lua function in Go with identical behavior.
local function encrypt(text, key) return text:gsub("%a", function(t) local base = (t:lower() == t and string.byte('a') or string.byte('A')) local r = t:byte() - base r = r + key r = r%26 r = r + base return string.char(r) end) end local function decrypt(text, key) return encrypt(text, -key) end...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Rewrite this program in C while keeping its functionality equivalent to the Mathematica version.
cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,n]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Write the same code in C# as shown below in Mathematica.
cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,n]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Translate this program into C++ but keep the logic exactly as in Mathematica.
cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,n]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Generate an equivalent Java version of this Mathematica code.
cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,n]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Please provide an equivalent version of this Mathematica code in Python.
cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,n]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Change the following Mathematica code into VB without altering its purpose.
cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,n]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Port the following code from Mathematica to Go with equivalent syntax and logic.
cypher[mesg_String,n_Integer]:=StringReplace[mesg,Flatten[Thread[Rule[#,RotateLeft[#,n]]]&/@CharacterRange@@@{{"a","z"},{"A","Z"}}]]
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Preserve the algorithm and functionality while converting the code from MATLAB to C.
function s = cipherCaesar(s, key) s = char( mod(s - 'A' + key, 25 ) + 'A'); end; function s = decipherCaesar(s, key) s = char( mod(s - 'A' - key, 25 ) + 'A'); end;
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Maintain the same structure and functionality when rewriting this code in C#.
function s = cipherCaesar(s, key) s = char( mod(s - 'A' + key, 25 ) + 'A'); end; function s = decipherCaesar(s, key) s = char( mod(s - 'A' - key, 25 ) + 'A'); end;
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Transform the following MATLAB implementation into C++, maintaining the same output and logic.
function s = cipherCaesar(s, key) s = char( mod(s - 'A' + key, 25 ) + 'A'); end; function s = decipherCaesar(s, key) s = char( mod(s - 'A' - key, 25 ) + 'A'); end;
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Produce a language-to-language conversion: from MATLAB to Java, same semantics.
function s = cipherCaesar(s, key) s = char( mod(s - 'A' + key, 25 ) + 'A'); end; function s = decipherCaesar(s, key) s = char( mod(s - 'A' - key, 25 ) + 'A'); end;
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Keep all operations the same but rewrite the snippet in Python.
function s = cipherCaesar(s, key) s = char( mod(s - 'A' + key, 25 ) + 'A'); end; function s = decipherCaesar(s, key) s = char( mod(s - 'A' - key, 25 ) + 'A'); end;
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Write the same code in VB as shown below in MATLAB.
function s = cipherCaesar(s, key) s = char( mod(s - 'A' + key, 25 ) + 'A'); end; function s = decipherCaesar(s, key) s = char( mod(s - 'A' - key, 25 ) + 'A'); end;
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Translate this program into Go but keep the logic exactly as in MATLAB.
function s = cipherCaesar(s, key) s = char( mod(s - 'A' + key, 25 ) + 'A'); end; function s = decipherCaesar(s, key) s = char( mod(s - 'A' - key, 25 ) + 'A'); end;
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Ensure the translated C code behaves exactly like the original Nim snippet.
import strutils proc caesar(s: string, k: int, decode = false): string = var k = if decode: 26 - k else: k result = "" for i in toUpper(s): if ord(i) >= 65 and ord(i) <= 90: result.add(chr((ord(i) - 65 + k) mod 26 + 65)) let msg = "The quick brown fox jumped over the lazy dogs" echo msg let enc = caes...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Rewrite this program in C# while keeping its functionality equivalent to the Nim version.
import strutils proc caesar(s: string, k: int, decode = false): string = var k = if decode: 26 - k else: k result = "" for i in toUpper(s): if ord(i) >= 65 and ord(i) <= 90: result.add(chr((ord(i) - 65 + k) mod 26 + 65)) let msg = "The quick brown fox jumped over the lazy dogs" echo msg let enc = caes...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Change the programming language of this snippet from Nim to C++ without modifying what it does.
import strutils proc caesar(s: string, k: int, decode = false): string = var k = if decode: 26 - k else: k result = "" for i in toUpper(s): if ord(i) >= 65 and ord(i) <= 90: result.add(chr((ord(i) - 65 + k) mod 26 + 65)) let msg = "The quick brown fox jumped over the lazy dogs" echo msg let enc = caes...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Translate this program into Java but keep the logic exactly as in Nim.
import strutils proc caesar(s: string, k: int, decode = false): string = var k = if decode: 26 - k else: k result = "" for i in toUpper(s): if ord(i) >= 65 and ord(i) <= 90: result.add(chr((ord(i) - 65 + k) mod 26 + 65)) let msg = "The quick brown fox jumped over the lazy dogs" echo msg let enc = caes...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Ensure the translated Python code behaves exactly like the original Nim snippet.
import strutils proc caesar(s: string, k: int, decode = false): string = var k = if decode: 26 - k else: k result = "" for i in toUpper(s): if ord(i) >= 65 and ord(i) <= 90: result.add(chr((ord(i) - 65 + k) mod 26 + 65)) let msg = "The quick brown fox jumped over the lazy dogs" echo msg let enc = caes...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Translate the given Nim code snippet into VB without altering its behavior.
import strutils proc caesar(s: string, k: int, decode = false): string = var k = if decode: 26 - k else: k result = "" for i in toUpper(s): if ord(i) >= 65 and ord(i) <= 90: result.add(chr((ord(i) - 65 + k) mod 26 + 65)) let msg = "The quick brown fox jumped over the lazy dogs" echo msg let enc = caes...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Convert this OCaml snippet to C and keep its semantics consistent.
fun readfile () = readfile [] | x = let val ln = readln () in if eof ln then rev x else readfile ` ln :: x end local val lower_a = ord #"a"; val lower_z = ord #"z"; val upper_a = ord #"A"; val upper_z = or...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Rewrite this program in C# while keeping its functionality equivalent to the OCaml version.
fun readfile () = readfile [] | x = let val ln = readln () in if eof ln then rev x else readfile ` ln :: x end local val lower_a = ord #"a"; val lower_z = ord #"z"; val upper_a = ord #"A"; val upper_z = or...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Produce a language-to-language conversion: from OCaml to C++, same semantics.
fun readfile () = readfile [] | x = let val ln = readln () in if eof ln then rev x else readfile ` ln :: x end local val lower_a = ord #"a"; val lower_z = ord #"z"; val upper_a = ord #"A"; val upper_z = or...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Write the same code in Java as shown below in OCaml.
fun readfile () = readfile [] | x = let val ln = readln () in if eof ln then rev x else readfile ` ln :: x end local val lower_a = ord #"a"; val lower_z = ord #"z"; val upper_a = ord #"A"; val upper_z = or...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Rewrite the snippet below in Python so it works the same as the original OCaml code.
fun readfile () = readfile [] | x = let val ln = readln () in if eof ln then rev x else readfile ` ln :: x end local val lower_a = ord #"a"; val lower_z = ord #"z"; val upper_a = ord #"A"; val upper_z = or...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Produce a language-to-language conversion: from OCaml to VB, same semantics.
fun readfile () = readfile [] | x = let val ln = readln () in if eof ln then rev x else readfile ` ln :: x end local val lower_a = ord #"a"; val lower_z = ord #"z"; val upper_a = ord #"A"; val upper_z = or...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Transform the following OCaml implementation into Go, maintaining the same output and logic.
fun readfile () = readfile [] | x = let val ln = readln () in if eof ln then rev x else readfile ` ln :: x end local val lower_a = ord #"a"; val lower_z = ord #"z"; val upper_a = ord #"A"; val upper_z = or...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Translate this program into C but keep the logic exactly as in Pascal.
Program CaesarCipher(output); procedure encrypt(var message: string; key: integer); var i: integer; begin for i := 1 to length(message) do case message[i] of 'A'..'Z': message[i] := chr(ord('A') + (ord(message[i]) - ord('A') + key) mod 26); 'a'..'z': message[i] := chr(ord('a') + (ord(...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Convert this Pascal snippet to C# and keep its semantics consistent.
Program CaesarCipher(output); procedure encrypt(var message: string; key: integer); var i: integer; begin for i := 1 to length(message) do case message[i] of 'A'..'Z': message[i] := chr(ord('A') + (ord(message[i]) - ord('A') + key) mod 26); 'a'..'z': message[i] := chr(ord('a') + (ord(...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Keep all operations the same but rewrite the snippet in C++.
Program CaesarCipher(output); procedure encrypt(var message: string; key: integer); var i: integer; begin for i := 1 to length(message) do case message[i] of 'A'..'Z': message[i] := chr(ord('A') + (ord(message[i]) - ord('A') + key) mod 26); 'a'..'z': message[i] := chr(ord('a') + (ord(...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Translate the given Pascal code snippet into Java without altering its behavior.
Program CaesarCipher(output); procedure encrypt(var message: string; key: integer); var i: integer; begin for i := 1 to length(message) do case message[i] of 'A'..'Z': message[i] := chr(ord('A') + (ord(message[i]) - ord('A') + key) mod 26); 'a'..'z': message[i] := chr(ord('a') + (ord(...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Can you help me rewrite this code in Python instead of Pascal, keeping it the same logically?
Program CaesarCipher(output); procedure encrypt(var message: string; key: integer); var i: integer; begin for i := 1 to length(message) do case message[i] of 'A'..'Z': message[i] := chr(ord('A') + (ord(message[i]) - ord('A') + key) mod 26); 'a'..'z': message[i] := chr(ord('a') + (ord(...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Write the same code in VB as shown below in Pascal.
Program CaesarCipher(output); procedure encrypt(var message: string; key: integer); var i: integer; begin for i := 1 to length(message) do case message[i] of 'A'..'Z': message[i] := chr(ord('A') + (ord(message[i]) - ord('A') + key) mod 26); 'a'..'z': message[i] := chr(ord('a') + (ord(...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Ensure the translated Go code behaves exactly like the original Pascal snippet.
Program CaesarCipher(output); procedure encrypt(var message: string; key: integer); var i: integer; begin for i := 1 to length(message) do case message[i] of 'A'..'Z': message[i] := chr(ord('A') + (ord(message[i]) - ord('A') + key) mod 26); 'a'..'z': message[i] := chr(ord('a') + (ord(...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Transform the following Perl implementation into C, maintaining the same output and logic.
sub caesar { my ($message, $key, $decode) = @_; $key = 26 - $key if $decode; $message =~ s/([A-Z])/chr(((ord(uc $1) - 65 + $key) % 26) + 65)/geir; } my $msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY'; my $enc = caesar($msg, 10); my $dec = caesar($enc, 10, 'decode'); print "msg: $msg\nenc: $enc...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Rewrite this program in C# while keeping its functionality equivalent to the Perl version.
sub caesar { my ($message, $key, $decode) = @_; $key = 26 - $key if $decode; $message =~ s/([A-Z])/chr(((ord(uc $1) - 65 + $key) % 26) + 65)/geir; } my $msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY'; my $enc = caesar($msg, 10); my $dec = caesar($enc, 10, 'decode'); print "msg: $msg\nenc: $enc...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Translate the given Perl code snippet into C++ without altering its behavior.
sub caesar { my ($message, $key, $decode) = @_; $key = 26 - $key if $decode; $message =~ s/([A-Z])/chr(((ord(uc $1) - 65 + $key) % 26) + 65)/geir; } my $msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY'; my $enc = caesar($msg, 10); my $dec = caesar($enc, 10, 'decode'); print "msg: $msg\nenc: $enc...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Convert this Perl block to Java, preserving its control flow and logic.
sub caesar { my ($message, $key, $decode) = @_; $key = 26 - $key if $decode; $message =~ s/([A-Z])/chr(((ord(uc $1) - 65 + $key) % 26) + 65)/geir; } my $msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY'; my $enc = caesar($msg, 10); my $dec = caesar($enc, 10, 'decode'); print "msg: $msg\nenc: $enc...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Generate a Python translation of this Perl snippet without changing its computational steps.
sub caesar { my ($message, $key, $decode) = @_; $key = 26 - $key if $decode; $message =~ s/([A-Z])/chr(((ord(uc $1) - 65 + $key) % 26) + 65)/geir; } my $msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY'; my $enc = caesar($msg, 10); my $dec = caesar($enc, 10, 'decode'); print "msg: $msg\nenc: $enc...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Change the following Perl code into VB without altering its purpose.
sub caesar { my ($message, $key, $decode) = @_; $key = 26 - $key if $decode; $message =~ s/([A-Z])/chr(((ord(uc $1) - 65 + $key) % 26) + 65)/geir; } my $msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY'; my $enc = caesar($msg, 10); my $dec = caesar($enc, 10, 'decode'); print "msg: $msg\nenc: $enc...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Write the same algorithm in Go as shown in this Perl implementation.
sub caesar { my ($message, $key, $decode) = @_; $key = 26 - $key if $decode; $message =~ s/([A-Z])/chr(((ord(uc $1) - 65 + $key) % 26) + 65)/geir; } my $msg = 'THE FIVE BOXING WIZARDS JUMP QUICKLY'; my $enc = caesar($msg, 10); my $dec = caesar($enc, 10, 'decode'); print "msg: $msg\nenc: $enc...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Write the same algorithm in C as shown in this PowerShell implementation.
function Get-CaesarCipher { Param ( [Parameter( Mandatory=$true,ValueFromPipeline=$true)] [string] $Text, [ValidateRange(1,25)] [int] $Key = 1, [switch] $Decode ) begin { $LowerAlpha = [char]'a'..[char]'z' $UpperAlpha = [char]'A'..[char]'Z' } process { $Chars = $Text.ToCharArray() function...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Preserve the algorithm and functionality while converting the code from PowerShell to C#.
function Get-CaesarCipher { Param ( [Parameter( Mandatory=$true,ValueFromPipeline=$true)] [string] $Text, [ValidateRange(1,25)] [int] $Key = 1, [switch] $Decode ) begin { $LowerAlpha = [char]'a'..[char]'z' $UpperAlpha = [char]'A'..[char]'Z' } process { $Chars = $Text.ToCharArray() function...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Convert the following code from PowerShell to C++, ensuring the logic remains intact.
function Get-CaesarCipher { Param ( [Parameter( Mandatory=$true,ValueFromPipeline=$true)] [string] $Text, [ValidateRange(1,25)] [int] $Key = 1, [switch] $Decode ) begin { $LowerAlpha = [char]'a'..[char]'z' $UpperAlpha = [char]'A'..[char]'Z' } process { $Chars = $Text.ToCharArray() function...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Rewrite the snippet below in Java so it works the same as the original PowerShell code.
function Get-CaesarCipher { Param ( [Parameter( Mandatory=$true,ValueFromPipeline=$true)] [string] $Text, [ValidateRange(1,25)] [int] $Key = 1, [switch] $Decode ) begin { $LowerAlpha = [char]'a'..[char]'z' $UpperAlpha = [char]'A'..[char]'Z' } process { $Chars = $Text.ToCharArray() function...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Write the same algorithm in Python as shown in this PowerShell implementation.
function Get-CaesarCipher { Param ( [Parameter( Mandatory=$true,ValueFromPipeline=$true)] [string] $Text, [ValidateRange(1,25)] [int] $Key = 1, [switch] $Decode ) begin { $LowerAlpha = [char]'a'..[char]'z' $UpperAlpha = [char]'A'..[char]'Z' } process { $Chars = $Text.ToCharArray() function...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Produce a functionally identical VB code for the snippet given in PowerShell.
function Get-CaesarCipher { Param ( [Parameter( Mandatory=$true,ValueFromPipeline=$true)] [string] $Text, [ValidateRange(1,25)] [int] $Key = 1, [switch] $Decode ) begin { $LowerAlpha = [char]'a'..[char]'z' $UpperAlpha = [char]'A'..[char]'Z' } process { $Chars = $Text.ToCharArray() function...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Generate a Go translation of this PowerShell snippet without changing its computational steps.
function Get-CaesarCipher { Param ( [Parameter( Mandatory=$true,ValueFromPipeline=$true)] [string] $Text, [ValidateRange(1,25)] [int] $Key = 1, [switch] $Decode ) begin { $LowerAlpha = [char]'a'..[char]'z' $UpperAlpha = [char]'A'..[char]'Z' } process { $Chars = $Text.ToCharArray() function...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Produce a language-to-language conversion: from R to C, same semantics.
ceasar <- function(x, key) { if (key < 0) { key <- 26 + key } old <- paste(letters, LETTERS, collapse="", sep="") new <- paste(substr(old, key * 2 + 1, 52), substr(old, 1, key * 2), sep="") chartr(old, new, x) } print(ceasar("hi",2)) print(ceasar("hi",20)) key <- 3 plaintext <- "The five boxin...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Convert the following code from R to C#, ensuring the logic remains intact.
ceasar <- function(x, key) { if (key < 0) { key <- 26 + key } old <- paste(letters, LETTERS, collapse="", sep="") new <- paste(substr(old, key * 2 + 1, 52), substr(old, 1, key * 2), sep="") chartr(old, new, x) } print(ceasar("hi",2)) print(ceasar("hi",20)) key <- 3 plaintext <- "The five boxin...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Preserve the algorithm and functionality while converting the code from R to C++.
ceasar <- function(x, key) { if (key < 0) { key <- 26 + key } old <- paste(letters, LETTERS, collapse="", sep="") new <- paste(substr(old, key * 2 + 1, 52), substr(old, 1, key * 2), sep="") chartr(old, new, x) } print(ceasar("hi",2)) print(ceasar("hi",20)) key <- 3 plaintext <- "The five boxin...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Port the following code from R to Java with equivalent syntax and logic.
ceasar <- function(x, key) { if (key < 0) { key <- 26 + key } old <- paste(letters, LETTERS, collapse="", sep="") new <- paste(substr(old, key * 2 + 1, 52), substr(old, 1, key * 2), sep="") chartr(old, new, x) } print(ceasar("hi",2)) print(ceasar("hi",20)) key <- 3 plaintext <- "The five boxin...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Ensure the translated Python code behaves exactly like the original R snippet.
ceasar <- function(x, key) { if (key < 0) { key <- 26 + key } old <- paste(letters, LETTERS, collapse="", sep="") new <- paste(substr(old, key * 2 + 1, 52), substr(old, 1, key * 2), sep="") chartr(old, new, x) } print(ceasar("hi",2)) print(ceasar("hi",20)) key <- 3 plaintext <- "The five boxin...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Ensure the translated VB code behaves exactly like the original R snippet.
ceasar <- function(x, key) { if (key < 0) { key <- 26 + key } old <- paste(letters, LETTERS, collapse="", sep="") new <- paste(substr(old, key * 2 + 1, 52), substr(old, 1, key * 2), sep="") chartr(old, new, x) } print(ceasar("hi",2)) print(ceasar("hi",20)) key <- 3 plaintext <- "The five boxin...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Please provide an equivalent version of this R code in Go.
ceasar <- function(x, key) { if (key < 0) { key <- 26 + key } old <- paste(letters, LETTERS, collapse="", sep="") new <- paste(substr(old, key * 2 + 1, 52), substr(old, 1, key * 2), sep="") chartr(old, new, x) } print(ceasar("hi",2)) print(ceasar("hi",20)) key <- 3 plaintext <- "The five boxin...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Port the provided Racket code into C while preserving the original functionality.
#lang racket (define A (char->integer #\A)) (define Z (char->integer #\Z)) (define a (char->integer #\a)) (define z (char->integer #\z)) (define (rotate c n) (define cnum (char->integer c)) (define (shift base) (integer->char (+ base (modulo (+ n (- cnum base)) 26)))) (cond [(<= A cnum Z) (shift A)] [...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Port the following code from Racket to C# with equivalent syntax and logic.
#lang racket (define A (char->integer #\A)) (define Z (char->integer #\Z)) (define a (char->integer #\a)) (define z (char->integer #\z)) (define (rotate c n) (define cnum (char->integer c)) (define (shift base) (integer->char (+ base (modulo (+ n (- cnum base)) 26)))) (cond [(<= A cnum Z) (shift A)] [...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Produce a language-to-language conversion: from Racket to C++, same semantics.
#lang racket (define A (char->integer #\A)) (define Z (char->integer #\Z)) (define a (char->integer #\a)) (define z (char->integer #\z)) (define (rotate c n) (define cnum (char->integer c)) (define (shift base) (integer->char (+ base (modulo (+ n (- cnum base)) 26)))) (cond [(<= A cnum Z) (shift A)] [...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Translate the given Racket code snippet into Java without altering its behavior.
#lang racket (define A (char->integer #\A)) (define Z (char->integer #\Z)) (define a (char->integer #\a)) (define z (char->integer #\z)) (define (rotate c n) (define cnum (char->integer c)) (define (shift base) (integer->char (+ base (modulo (+ n (- cnum base)) 26)))) (cond [(<= A cnum Z) (shift A)] [...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Port the following code from Racket to Python with equivalent syntax and logic.
#lang racket (define A (char->integer #\A)) (define Z (char->integer #\Z)) (define a (char->integer #\a)) (define z (char->integer #\z)) (define (rotate c n) (define cnum (char->integer c)) (define (shift base) (integer->char (+ base (modulo (+ n (- cnum base)) 26)))) (cond [(<= A cnum Z) (shift A)] [...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Maintain the same structure and functionality when rewriting this code in VB.
#lang racket (define A (char->integer #\A)) (define Z (char->integer #\Z)) (define a (char->integer #\a)) (define z (char->integer #\z)) (define (rotate c n) (define cnum (char->integer c)) (define (shift base) (integer->char (+ base (modulo (+ n (- cnum base)) 26)))) (cond [(<= A cnum Z) (shift A)] [...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Ensure the translated Go code behaves exactly like the original Racket snippet.
#lang racket (define A (char->integer #\A)) (define Z (char->integer #\Z)) (define a (char->integer #\a)) (define z (char->integer #\z)) (define (rotate c n) (define cnum (char->integer c)) (define (shift base) (integer->char (+ base (modulo (+ n (- cnum base)) 26)))) (cond [(<= A cnum Z) (shift A)] [...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Change the following COBOL code into C without altering its purpose.
identification division. program-id. caesar. data division. 1 msg pic x(50) value "The quick brown fox jumped over the lazy dog.". 1 offset binary pic 9(4) value 7. 1 from-chars pic x(52). 1 to-chars pic x(52). 1 tabl. 2 pic x(26) value "abcdefg...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Keep all operations the same but rewrite the snippet in C#.
identification division. program-id. caesar. data division. 1 msg pic x(50) value "The quick brown fox jumped over the lazy dog.". 1 offset binary pic 9(4) value 7. 1 from-chars pic x(52). 1 to-chars pic x(52). 1 tabl. 2 pic x(26) value "abcdefg...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Generate a C++ translation of this COBOL snippet without changing its computational steps.
identification division. program-id. caesar. data division. 1 msg pic x(50) value "The quick brown fox jumped over the lazy dog.". 1 offset binary pic 9(4) value 7. 1 from-chars pic x(52). 1 to-chars pic x(52). 1 tabl. 2 pic x(26) value "abcdefg...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Keep all operations the same but rewrite the snippet in Java.
identification division. program-id. caesar. data division. 1 msg pic x(50) value "The quick brown fox jumped over the lazy dog.". 1 offset binary pic 9(4) value 7. 1 from-chars pic x(52). 1 to-chars pic x(52). 1 tabl. 2 pic x(26) value "abcdefg...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Port the provided COBOL code into Python while preserving the original functionality.
identification division. program-id. caesar. data division. 1 msg pic x(50) value "The quick brown fox jumped over the lazy dog.". 1 offset binary pic 9(4) value 7. 1 from-chars pic x(52). 1 to-chars pic x(52). 1 tabl. 2 pic x(26) value "abcdefg...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Write a version of this COBOL function in VB with identical behavior.
identification division. program-id. caesar. data division. 1 msg pic x(50) value "The quick brown fox jumped over the lazy dog.". 1 offset binary pic 9(4) value 7. 1 from-chars pic x(52). 1 to-chars pic x(52). 1 tabl. 2 pic x(26) value "abcdefg...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Port the provided COBOL code into Go while preserving the original functionality.
identification division. program-id. caesar. data division. 1 msg pic x(50) value "The quick brown fox jumped over the lazy dog.". 1 offset binary pic 9(4) value 7. 1 from-chars pic x(52). 1 to-chars pic x(52). 1 tabl. 2 pic x(26) value "abcdefg...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Convert this REXX block to C, preserving its control flow and logic.
options replace format comments java crossref savelog symbols nobinary messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13] loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, key:' keys[k_].ri...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Keep all operations the same but rewrite the snippet in C#.
options replace format comments java crossref savelog symbols nobinary messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13] loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, key:' keys[k_].ri...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Convert the following code from REXX to C++, ensuring the logic remains intact.
options replace format comments java crossref savelog symbols nobinary messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13] loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, key:' keys[k_].ri...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Keep all operations the same but rewrite the snippet in Java.
options replace format comments java crossref savelog symbols nobinary messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13] loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, key:' keys[k_].ri...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Port the provided REXX code into Python while preserving the original functionality.
options replace format comments java crossref savelog symbols nobinary messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13] loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, key:' keys[k_].ri...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Translate this program into VB but keep the logic exactly as in REXX.
options replace format comments java crossref savelog symbols nobinary messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13] loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, key:' keys[k_].ri...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Change the programming language of this snippet from REXX to Go without modifying what it does.
options replace format comments java crossref savelog symbols nobinary messages = [ - 'The five boxing wizards jump quickly', - 'Attack at dawn!', - 'HI'] keys = [1, 2, 20, 25, 13] loop m_ = 0 to messages.length - 1 in = messages[m_] loop k_ = 0 to keys.length - 1 say 'Caesar cipher, key:' keys[k_].ri...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Change the following Ruby code into C without altering its purpose.
class String ALFABET = ("A".."Z").to_a def caesar_cipher(num) self.tr(ALFABET.join, ALFABET.rotate(num).join) end end encypted = "THEYBROKEOURCIPHEREVERYONECANREADTHIS".caesar_cipher(3) decrypted = encypted.caesar_cipher(-3)
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Generate a C# translation of this Ruby snippet without changing its computational steps.
class String ALFABET = ("A".."Z").to_a def caesar_cipher(num) self.tr(ALFABET.join, ALFABET.rotate(num).join) end end encypted = "THEYBROKEOURCIPHEREVERYONECANREADTHIS".caesar_cipher(3) decrypted = encypted.caesar_cipher(-3)
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Port the provided Ruby code into C++ while preserving the original functionality.
class String ALFABET = ("A".."Z").to_a def caesar_cipher(num) self.tr(ALFABET.join, ALFABET.rotate(num).join) end end encypted = "THEYBROKEOURCIPHEREVERYONECANREADTHIS".caesar_cipher(3) decrypted = encypted.caesar_cipher(-3)
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Port the following code from Ruby to Python with equivalent syntax and logic.
class String ALFABET = ("A".."Z").to_a def caesar_cipher(num) self.tr(ALFABET.join, ALFABET.rotate(num).join) end end encypted = "THEYBROKEOURCIPHEREVERYONECANREADTHIS".caesar_cipher(3) decrypted = encypted.caesar_cipher(-3)
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Generate a VB translation of this Ruby snippet without changing its computational steps.
class String ALFABET = ("A".."Z").to_a def caesar_cipher(num) self.tr(ALFABET.join, ALFABET.rotate(num).join) end end encypted = "THEYBROKEOURCIPHEREVERYONECANREADTHIS".caesar_cipher(3) decrypted = encypted.caesar_cipher(-3)
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Translate the given Ruby code snippet into Go without altering its behavior.
class String ALFABET = ("A".."Z").to_a def caesar_cipher(num) self.tr(ALFABET.join, ALFABET.rotate(num).join) end end encypted = "THEYBROKEOURCIPHEREVERYONECANREADTHIS".caesar_cipher(3) decrypted = encypted.caesar_cipher(-3)
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Change the programming language of this snippet from Scala to C without modifying what it does.
object Caesar { fun encrypt(s: String, key: Int): String { val offset = key % 26 if (offset == 0) return s var d: Char val chars = CharArray(s.length) for ((index, c) in s.withIndex()) { if (c in 'A'..'Z') { d = c + offset if (d ...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Port the provided Scala code into C# while preserving the original functionality.
object Caesar { fun encrypt(s: String, key: Int): String { val offset = key % 26 if (offset == 0) return s var d: Char val chars = CharArray(s.length) for ((index, c) in s.withIndex()) { if (c in 'A'..'Z') { d = c + offset if (d ...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Write the same algorithm in C++ as shown in this Scala implementation.
object Caesar { fun encrypt(s: String, key: Int): String { val offset = key % 26 if (offset == 0) return s var d: Char val chars = CharArray(s.length) for ((index, c) in s.withIndex()) { if (c in 'A'..'Z') { d = c + offset if (d ...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Ensure the translated Java code behaves exactly like the original Scala snippet.
object Caesar { fun encrypt(s: String, key: Int): String { val offset = key % 26 if (offset == 0) return s var d: Char val chars = CharArray(s.length) for ((index, c) in s.withIndex()) { if (c in 'A'..'Z') { d = c + offset if (d ...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Convert this Scala block to Python, preserving its control flow and logic.
object Caesar { fun encrypt(s: String, key: Int): String { val offset = key % 26 if (offset == 0) return s var d: Char val chars = CharArray(s.length) for ((index, c) in s.withIndex()) { if (c in 'A'..'Z') { d = c + offset if (d ...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Port the provided Scala code into VB while preserving the original functionality.
object Caesar { fun encrypt(s: String, key: Int): String { val offset = key % 26 if (offset == 0) return s var d: Char val chars = CharArray(s.length) for ((index, c) in s.withIndex()) { if (c in 'A'..'Z') { d = c + offset if (d ...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Change the following Scala code into Go without altering its purpose.
object Caesar { fun encrypt(s: String, key: Int): String { val offset = key % 26 if (offset == 0) return s var d: Char val chars = CharArray(s.length) for ((index, c) in s.withIndex()) { if (c in 'A'..'Z') { d = c + offset if (d ...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Maintain the same structure and functionality when rewriting this code in C.
func usage(_ e:String) { print("error: \(e)") print("./caeser -e 19 a-secret-string") print("./caeser -d 19 tskxvjxlskljafz") } func charIsValid(_ c:Character) -> Bool { return c.isASCII && ( c.isLowercase || 45 == c.asciiValue ) } func charRotate(_ c:Character, _ by:Int) -> Character { var cv:UInt8! = c.a...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Produce a language-to-language conversion: from Swift to C#, same semantics.
func usage(_ e:String) { print("error: \(e)") print("./caeser -e 19 a-secret-string") print("./caeser -d 19 tskxvjxlskljafz") } func charIsValid(_ c:Character) -> Bool { return c.isASCII && ( c.isLowercase || 45 == c.asciiValue ) } func charRotate(_ c:Character, _ by:Int) -> Character { var cv:UInt8! = c.a...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...
Write the same code in C++ as shown below in Swift.
func usage(_ e:String) { print("error: \(e)") print("./caeser -e 19 a-secret-string") print("./caeser -d 19 tskxvjxlskljafz") } func charIsValid(_ c:Character) -> Bool { return c.isASCII && ( c.isLowercase || 45 == c.asciiValue ) } func charRotate(_ c:Character, _ by:Int) -> Character { var cv:UInt8! = c.a...
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
Change the programming language of this snippet from Swift to Java without modifying what it does.
func usage(_ e:String) { print("error: \(e)") print("./caeser -e 19 a-secret-string") print("./caeser -d 19 tskxvjxlskljafz") } func charIsValid(_ c:Character) -> Bool { return c.isASCII && ( c.isLowercase || 45 == c.asciiValue ) } func charRotate(_ c:Character, _ by:Int) -> Character { var cv:UInt8! = c.a...
public class Cipher { public static void main(String[] args) { String str = "The quick brown fox Jumped over the lazy Dog"; System.out.println( Cipher.encode( str, 12 )); System.out.println( Cipher.decode( Cipher.encode( str, 12), 12 )); } public static String decode(String enc, i...
Please provide an equivalent version of this Swift code in Python.
func usage(_ e:String) { print("error: \(e)") print("./caeser -e 19 a-secret-string") print("./caeser -d 19 tskxvjxlskljafz") } func charIsValid(_ c:Character) -> Bool { return c.isASCII && ( c.isLowercase || 45 == c.asciiValue ) } func charRotate(_ c:Character, _ by:Int) -> Character { var cv:UInt8! = c.a...
fun caesar(s, k, decode: false): if decode: k = 26 - k result = '' for i in s.uppercase() where 65 <= ord(i) <= 90: result.push! char(ord(i) - 65 + k) mod 26 + 65 return result let message = "The quick brown fox jumped over the lazy dogs" let encrypted = caesar(msg, 11) let decrypted = ...
Port the following code from Swift to VB with equivalent syntax and logic.
func usage(_ e:String) { print("error: \(e)") print("./caeser -e 19 a-secret-string") print("./caeser -d 19 tskxvjxlskljafz") } func charIsValid(_ c:Character) -> Bool { return c.isASCII && ( c.isLowercase || 45 == c.asciiValue ) } func charRotate(_ c:Character, _ by:Int) -> Character { var cv:UInt8! = c.a...
Option Explicit Sub Main_Caesar() Dim ch As String ch = Caesar_Cipher("CAESAR: Who is it in the press that calls on me? I hear a tongue, shriller than all the music, Cry Debug.Print ch Debug.Print Caesar_Cipher(ch, -14) End Sub Function Caesar_Cipher(sText As String, lngNumber As Long) As String Dim Tbl,...
Maintain the same structure and functionality when rewriting this code in Go.
func usage(_ e:String) { print("error: \(e)") print("./caeser -e 19 a-secret-string") print("./caeser -d 19 tskxvjxlskljafz") } func charIsValid(_ c:Character) -> Bool { return c.isASCII && ( c.isLowercase || 45 == c.asciiValue ) } func charRotate(_ c:Character, _ by:Int) -> Character { var cv:UInt8! = c.a...
package main import ( "fmt" "strings" ) type ckey struct { enc, dec func(rune) rune } func newCaesar(k int) (*ckey, bool) { if k < 1 || k > 25 { return nil, false } rk := rune(k) return &ckey{ enc: func(c rune) rune { if c >= 'a' && c <= 'z'-rk || c >= 'A' && c...
Rewrite the snippet below in C so it works the same as the original Tcl code.
package require Tcl 8.6; oo::class create Caesar { variable encryptMap decryptMap constructor shift { for {set i 0} {$i < 26} {incr i} { append encryptMap [format "%c %c %c %c " \ [expr {$i+65}] [expr {($i+$shift)%26+65}] \ [expr {$i+97}] [expr {($i+$shift)%26+97}]] append decr...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define caesar(x) rot(13, x) #define decaesar(x) rot(13, x) #define decrypt_rot(x, y) rot((26-x), y) void rot(int c, char *str) { int l = strlen(str); const char* alpha_low = "abcdefghijklmnopqrstuvwxyz"; const...
Port the following code from Tcl to C# with equivalent syntax and logic.
package require Tcl 8.6; oo::class create Caesar { variable encryptMap decryptMap constructor shift { for {set i 0} {$i < 26} {incr i} { append encryptMap [format "%c %c %c %c " \ [expr {$i+65}] [expr {($i+$shift)%26+65}] \ [expr {$i+97}] [expr {($i+$shift)%26+97}]] append decr...
using System; using System.Linq; namespace CaesarCypher { class Program { static char Encrypt(char ch, int code) { if (!char.IsLetter(ch)) return ch; char offset = char.IsUpper(ch) ? 'A' : 'a'; return (char)((ch + code - offset) % 26 + offset); } ...