Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Write a version of this Clojure function in Java with identical behavior. | (defn encrypt-character [offset c]
(if (Character/isLetter c)
(let [v (int c)
base (if (>= v (int \a))
(int \a)
(int \A))
offset (mod offset 26)]
(char (+ (mod (+ (- v base) offset) 26)
base)))
c))
(defn encrypt [offset text]
(app... | 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 Clojure to Python with equivalent syntax and logic. | (defn encrypt-character [offset c]
(if (Character/isLetter c)
(let [v (int c)
base (if (>= v (int \a))
(int \a)
(int \A))
offset (mod offset 26)]
(char (+ (mod (+ (- v base) offset) 26)
base)))
c))
(defn encrypt [offset text]
(app... | 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 Clojure to VB, same semantics. | (defn encrypt-character [offset c]
(if (Character/isLetter c)
(let [v (int c)
base (if (>= v (int \a))
(int \a)
(int \A))
offset (mod offset 26)]
(char (+ (mod (+ (- v base) offset) 26)
base)))
c))
(defn encrypt [offset text]
(app... | 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 an equivalent Go version of this Clojure code. | (defn encrypt-character [offset c]
(if (Character/isLetter c)
(let [v (int c)
base (if (>= v (int \a))
(int \a)
(int \A))
offset (mod offset 26)]
(char (+ (mod (+ (- v base) offset) 26)
base)))
c))
(defn encrypt [offset text]
(app... | 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... |
Please provide an equivalent version of this Common_Lisp code in C. | (defun encipher-char (ch key)
(let* ((c (char-code ch)) (la (char-code #\a)) (ua (char-code #\A))
(base (cond ((<= la c (char-code #\z)) la)
((<= ua c (char-code #\Z)) ua)
(nil))))
(if base (code-char (+ (mod (+ (- c base) key) 26) base)) ch)))
(defun caesa... | #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#. | (defun encipher-char (ch key)
(let* ((c (char-code ch)) (la (char-code #\a)) (ua (char-code #\A))
(base (cond ((<= la c (char-code #\z)) la)
((<= ua c (char-code #\Z)) ua)
(nil))))
(if base (code-char (+ (mod (+ (- c base) key) 26) base)) ch)))
(defun caesa... | 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 Common_Lisp to C++, ensuring the logic remains intact. | (defun encipher-char (ch key)
(let* ((c (char-code ch)) (la (char-code #\a)) (ua (char-code #\A))
(base (cond ((<= la c (char-code #\z)) la)
((<= ua c (char-code #\Z)) ua)
(nil))))
(if base (code-char (+ (mod (+ (- c base) key) 26) base)) ch)))
(defun caesa... | #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. | (defun encipher-char (ch key)
(let* ((c (char-code ch)) (la (char-code #\a)) (ua (char-code #\A))
(base (cond ((<= la c (char-code #\z)) la)
((<= ua c (char-code #\Z)) ua)
(nil))))
(if base (code-char (+ (mod (+ (- c base) key) 26) base)) ch)))
(defun caesa... | 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... |
Maintain the same structure and functionality when rewriting this code in Python. | (defun encipher-char (ch key)
(let* ((c (char-code ch)) (la (char-code #\a)) (ua (char-code #\A))
(base (cond ((<= la c (char-code #\z)) la)
((<= ua c (char-code #\Z)) ua)
(nil))))
(if base (code-char (+ (mod (+ (- c base) key) 26) base)) ch)))
(defun caesa... | 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 Common_Lisp. | (defun encipher-char (ch key)
(let* ((c (char-code ch)) (la (char-code #\a)) (ua (char-code #\A))
(base (cond ((<= la c (char-code #\z)) la)
((<= ua c (char-code #\Z)) ua)
(nil))))
(if base (code-char (+ (mod (+ (- c base) key) 26) base)) ch)))
(defun caesa... | 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 Common_Lisp code snippet into Go without altering its behavior. | (defun encipher-char (ch key)
(let* ((c (char-code ch)) (la (char-code #\a)) (ua (char-code #\A))
(base (cond ((<= la c (char-code #\z)) la)
((<= ua c (char-code #\Z)) ua)
(nil))))
(if base (code-char (+ (mod (+ (- c base) key) 26) base)) ch)))
(defun caesa... | 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 D implementation into C, maintaining the same output and logic. | import std.stdio, std.traits;
S rot(S)(in S s, in int key) pure nothrow @safe
if (isSomeString!S) {
auto res = s.dup;
foreach (immutable i, ref c; res) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26... | #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 D snippet to C# and keep its semantics consistent. | import std.stdio, std.traits;
S rot(S)(in S s, in int key) pure nothrow @safe
if (isSomeString!S) {
auto res = s.dup;
foreach (immutable i, ref c; res) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26... | 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 a version of this D function in C++ with identical behavior. | import std.stdio, std.traits;
S rot(S)(in S s, in int key) pure nothrow @safe
if (isSomeString!S) {
auto res = s.dup;
foreach (immutable i, ref c; res) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26... | #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"... |
Preserve the algorithm and functionality while converting the code from D to Java. | import std.stdio, std.traits;
S rot(S)(in S s, in int key) pure nothrow @safe
if (isSomeString!S) {
auto res = s.dup;
foreach (immutable i, ref c; res) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26... | 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 D, keeping it the same logically? | import std.stdio, std.traits;
S rot(S)(in S s, in int key) pure nothrow @safe
if (isSomeString!S) {
auto res = s.dup;
foreach (immutable i, ref c; res) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26... | 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 = ... |
Rewrite the snippet below in VB so it works the same as the original D code. | import std.stdio, std.traits;
S rot(S)(in S s, in int key) pure nothrow @safe
if (isSomeString!S) {
auto res = s.dup;
foreach (immutable i, ref c; res) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26... | 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,... |
Produce a language-to-language conversion: from D to Go, same semantics. | import std.stdio, std.traits;
S rot(S)(in S s, in int key) pure nothrow @safe
if (isSomeString!S) {
auto res = s.dup;
foreach (immutable i, ref c; res) {
if ('a' <= c && c <= 'z')
c = ((c - 'a' + key) % 26 + 'a');
else if ('A' <= c && c <= 'Z')
c = ((c - 'A' + key) % 26... | 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... |
Can you help me rewrite this code in C instead of Elixir, keeping it the same logically? | defmodule Caesar_cipher do
defp set_map(map, range, key) do
org = Enum.map(range, &List.to_string [&1])
{a, b} = Enum.split(org, key)
Enum.zip(org, b ++ a) |> Enum.into(map)
end
def encode(text, key) do
map = Map.new |> set_map(?a..?z, key) |> set_map(?A..?Z, key)
String.graphemes(text) |> ... | #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 Elixir to C#, ensuring the logic remains intact. | defmodule Caesar_cipher do
defp set_map(map, range, key) do
org = Enum.map(range, &List.to_string [&1])
{a, b} = Enum.split(org, key)
Enum.zip(org, b ++ a) |> Enum.into(map)
end
def encode(text, key) do
map = Map.new |> set_map(?a..?z, key) |> set_map(?A..?Z, key)
String.graphemes(text) |> ... | 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 Elixir implementation. | defmodule Caesar_cipher do
defp set_map(map, range, key) do
org = Enum.map(range, &List.to_string [&1])
{a, b} = Enum.split(org, key)
Enum.zip(org, b ++ a) |> Enum.into(map)
end
def encode(text, key) do
map = Map.new |> set_map(?a..?z, key) |> set_map(?A..?Z, key)
String.graphemes(text) |> ... | #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 Elixir snippet to Java and keep its semantics consistent. | defmodule Caesar_cipher do
defp set_map(map, range, key) do
org = Enum.map(range, &List.to_string [&1])
{a, b} = Enum.split(org, key)
Enum.zip(org, b ++ a) |> Enum.into(map)
end
def encode(text, key) do
map = Map.new |> set_map(?a..?z, key) |> set_map(?A..?Z, key)
String.graphemes(text) |> ... | 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. | defmodule Caesar_cipher do
defp set_map(map, range, key) do
org = Enum.map(range, &List.to_string [&1])
{a, b} = Enum.split(org, key)
Enum.zip(org, b ++ a) |> Enum.into(map)
end
def encode(text, key) do
map = Map.new |> set_map(?a..?z, key) |> set_map(?A..?Z, key)
String.graphemes(text) |> ... | 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. | defmodule Caesar_cipher do
defp set_map(map, range, key) do
org = Enum.map(range, &List.to_string [&1])
{a, b} = Enum.split(org, key)
Enum.zip(org, b ++ a) |> Enum.into(map)
end
def encode(text, key) do
map = Map.new |> set_map(?a..?z, key) |> set_map(?A..?Z, key)
String.graphemes(text) |> ... | 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 Elixir to Go without modifying what it does. | defmodule Caesar_cipher do
defp set_map(map, range, key) do
org = Enum.map(range, &List.to_string [&1])
{a, b} = Enum.split(org, key)
Enum.zip(org, b ++ a) |> Enum.into(map)
end
def encode(text, key) do
map = Map.new |> set_map(?a..?z, key) |> set_map(?A..?Z, key)
String.graphemes(text) |> ... | 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 Erlang code. |
-module(ceasar).
-export([main/2]).
rot(Char,Key) when (Char >= $A) and (Char =< $Z) or
(Char >= $a) and (Char =< $z) ->
Offset = $A + Char band 32,
N = Char - Offset,
Offset + (N + Key) rem 26;
rot(Char, _Key) ->
Char.
key(Key) when Key < 0 ->
26 + Key rem 26;
key(Key) when Key > ... | #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 Erlang to C#, ensuring the logic remains intact. |
-module(ceasar).
-export([main/2]).
rot(Char,Key) when (Char >= $A) and (Char =< $Z) or
(Char >= $a) and (Char =< $z) ->
Offset = $A + Char band 32,
N = Char - Offset,
Offset + (N + Key) rem 26;
rot(Char, _Key) ->
Char.
key(Key) when Key < 0 ->
26 + Key rem 26;
key(Key) when Key > ... | 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 following code from Erlang to C++ with equivalent syntax and logic. |
-module(ceasar).
-export([main/2]).
rot(Char,Key) when (Char >= $A) and (Char =< $Z) or
(Char >= $a) and (Char =< $z) ->
Offset = $A + Char band 32,
N = Char - Offset,
Offset + (N + Key) rem 26;
rot(Char, _Key) ->
Char.
key(Key) when Key < 0 ->
26 + Key rem 26;
key(Key) when Key > ... | #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 this program in Java while keeping its functionality equivalent to the Erlang version. |
-module(ceasar).
-export([main/2]).
rot(Char,Key) when (Char >= $A) and (Char =< $Z) or
(Char >= $a) and (Char =< $z) ->
Offset = $A + Char band 32,
N = Char - Offset,
Offset + (N + Key) rem 26;
rot(Char, _Key) ->
Char.
key(Key) when Key < 0 ->
26 + Key rem 26;
key(Key) when Key > ... | 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... |
Translate this program into Python but keep the logic exactly as in Erlang. |
-module(ceasar).
-export([main/2]).
rot(Char,Key) when (Char >= $A) and (Char =< $Z) or
(Char >= $a) and (Char =< $z) ->
Offset = $A + Char band 32,
N = Char - Offset,
Offset + (N + Key) rem 26;
rot(Char, _Key) ->
Char.
key(Key) when Key < 0 ->
26 + Key rem 26;
key(Key) when Key > ... | 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. |
-module(ceasar).
-export([main/2]).
rot(Char,Key) when (Char >= $A) and (Char =< $Z) or
(Char >= $a) and (Char =< $z) ->
Offset = $A + Char band 32,
N = Char - Offset,
Offset + (N + Key) rem 26;
rot(Char, _Key) ->
Char.
key(Key) when Key < 0 ->
26 + Key rem 26;
key(Key) when Key > ... | 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,... |
Can you help me rewrite this code in Go instead of Erlang, keeping it the same logically? |
-module(ceasar).
-export([main/2]).
rot(Char,Key) when (Char >= $A) and (Char =< $Z) or
(Char >= $a) and (Char =< $z) ->
Offset = $A + Char band 32,
N = Char - Offset,
Offset + (N + Key) rem 26;
rot(Char, _Key) ->
Char.
key(Key) when Key < 0 ->
26 + Key rem 26;
key(Key) when Key > ... | 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 F# code into C while preserving the original functionality. | module caesar =
open System
let private cipher n s =
let shift c =
if Char.IsLetter c then
let a = (if Char.IsLower c then 'a' else 'A') |> int
(int c - a + n) % 26 + a |> char
else c
String.map shift s
let encrypt n = cipher n
le... | #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 the snippet below in C# so it works the same as the original F# code. | module caesar =
open System
let private cipher n s =
let shift c =
if Char.IsLetter c then
let a = (if Char.IsLower c then 'a' else 'A') |> int
(int c - a + n) % 26 + a |> char
else c
String.map shift s
let encrypt n = cipher n
le... | 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 following F# code into C++ without altering its purpose. | module caesar =
open System
let private cipher n s =
let shift c =
if Char.IsLetter c then
let a = (if Char.IsLower c then 'a' else 'A') |> int
(int c - a + n) % 26 + a |> char
else c
String.map shift s
let encrypt n = cipher n
le... | #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"... |
Maintain the same structure and functionality when rewriting this code in Java. | module caesar =
open System
let private cipher n s =
let shift c =
if Char.IsLetter c then
let a = (if Char.IsLower c then 'a' else 'A') |> int
(int c - a + n) % 26 + a |> char
else c
String.map shift s
let encrypt n = cipher n
le... | 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 an equivalent Python version of this F# code. | module caesar =
open System
let private cipher n s =
let shift c =
if Char.IsLetter c then
let a = (if Char.IsLower c then 'a' else 'A') |> int
(int c - a + n) % 26 + a |> char
else c
String.map shift s
let encrypt n = cipher n
le... | 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 an equivalent VB version of this F# code. | module caesar =
open System
let private cipher n s =
let shift c =
if Char.IsLetter c then
let a = (if Char.IsLower c then 'a' else 'A') |> int
(int c - a + n) % 26 + a |> char
else c
String.map shift s
let encrypt n = cipher n
le... | 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,... |
Can you help me rewrite this code in Go instead of F#, keeping it the same logically? | module caesar =
open System
let private cipher n s =
let shift c =
if Char.IsLetter c then
let a = (if Char.IsLower c then 'a' else 'A') |> int
(int c - a + n) % 26 + a |> char
else c
String.map shift s
let encrypt n = cipher n
le... | 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 Factor implementation into C, maintaining the same output and logic. | USING: io kernel locals math sequences unicode.categories ;
IN: rosetta-code.caesar-cipher
:: cipher ( n s -- s' )
[| c |
c Letter? [
c letter? CHAR: a CHAR: A ? :> a
c a - n + 26 mod a +
]
[ c ] if
] :> shift
s [ shift call ] map ;
: encrypt ( n s -- s'... | #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 algorithm in C# as shown in this Factor implementation. | USING: io kernel locals math sequences unicode.categories ;
IN: rosetta-code.caesar-cipher
:: cipher ( n s -- s' )
[| c |
c Letter? [
c letter? CHAR: a CHAR: A ? :> a
c a - n + 26 mod a +
]
[ c ] if
] :> shift
s [ shift call ] map ;
: encrypt ( n s -- s'... | 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 following code from Factor to C++ with equivalent syntax and logic. | USING: io kernel locals math sequences unicode.categories ;
IN: rosetta-code.caesar-cipher
:: cipher ( n s -- s' )
[| c |
c Letter? [
c letter? CHAR: a CHAR: A ? :> a
c a - n + 26 mod a +
]
[ c ] if
] :> shift
s [ shift call ] map ;
: encrypt ( n s -- s'... | #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 Factor snippet. | USING: io kernel locals math sequences unicode.categories ;
IN: rosetta-code.caesar-cipher
:: cipher ( n s -- s' )
[| c |
c Letter? [
c letter? CHAR: a CHAR: A ? :> a
c a - n + 26 mod a +
]
[ c ] if
] :> shift
s [ shift call ] map ;
: encrypt ( n s -- s'... | 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... |
Maintain the same structure and functionality when rewriting this code in Python. | USING: io kernel locals math sequences unicode.categories ;
IN: rosetta-code.caesar-cipher
:: cipher ( n s -- s' )
[| c |
c Letter? [
c letter? CHAR: a CHAR: A ? :> a
c a - n + 26 mod a +
]
[ c ] if
] :> shift
s [ shift call ] map ;
: encrypt ( n s -- s'... | 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 Factor function in VB with identical behavior. | USING: io kernel locals math sequences unicode.categories ;
IN: rosetta-code.caesar-cipher
:: cipher ( n s -- s' )
[| c |
c Letter? [
c letter? CHAR: a CHAR: A ? :> a
c a - n + 26 mod a +
]
[ c ] if
] :> shift
s [ shift call ] map ;
: encrypt ( n s -- s'... | 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 Factor code into Go without altering its purpose. | USING: io kernel locals math sequences unicode.categories ;
IN: rosetta-code.caesar-cipher
:: cipher ( n s -- s' )
[| c |
c Letter? [
c letter? CHAR: a CHAR: A ? :> a
c a - n + 26 mod a +
]
[ c ] if
] :> shift
s [ shift call ] map ;
: encrypt ( n s -- s'... | 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... |
Can you help me rewrite this code in C instead of Forth, keeping it the same logically? |
: modulate
tuck n:- 26 n:+ 26 n:mod n:+ ;
: caesar
>r
s:map rdrop ;
"The five boxing wizards jump quickly!"
dup . cr
1 caesar dup . cr
-1 caesar . cr
bye
| #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 Forth snippet to C# and keep its semantics consistent. |
: modulate
tuck n:- 26 n:+ 26 n:mod n:+ ;
: caesar
>r
s:map rdrop ;
"The five boxing wizards jump quickly!"
dup . cr
1 caesar dup . cr
-1 caesar . cr
bye
| 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 Forth implementation. |
: modulate
tuck n:- 26 n:+ 26 n:mod n:+ ;
: caesar
>r
s:map rdrop ;
"The five boxing wizards jump quickly!"
dup . cr
1 caesar dup . cr
-1 caesar . cr
bye
| #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. |
: modulate
tuck n:- 26 n:+ 26 n:mod n:+ ;
: caesar
>r
s:map rdrop ;
"The five boxing wizards jump quickly!"
dup . cr
1 caesar dup . cr
-1 caesar . cr
bye
| 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... |
Transform the following Forth implementation into Python, maintaining the same output and logic. |
: modulate
tuck n:- 26 n:+ 26 n:mod n:+ ;
: caesar
>r
s:map rdrop ;
"The five boxing wizards jump quickly!"
dup . cr
1 caesar dup . cr
-1 caesar . cr
bye
| 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 = ... |
Convert this Forth snippet to VB and keep its semantics consistent. |
: modulate
tuck n:- 26 n:+ 26 n:mod n:+ ;
: caesar
>r
s:map rdrop ;
"The five boxing wizards jump quickly!"
dup . cr
1 caesar dup . cr
-1 caesar . cr
bye
| 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 Forth snippet. |
: modulate
tuck n:- 26 n:+ 26 n:mod n:+ ;
: caesar
>r
s:map rdrop ;
"The five boxing wizards jump quickly!"
dup . cr
1 caesar dup . cr
-1 caesar . cr
bye
| 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 the following code from Fortran to C#, ensuring the logic remains intact. | program Caesar_Cipher
implicit none
integer, parameter :: key = 3
character(43) :: message = "The five boxing wizards jump quickly"
write(*, "(2a)") "Original message = ", message
call encrypt(message)
write(*, "(2a)") "Encrypted message = ", message
call decrypt(message)
write(*, "(2a)") "Decry... | 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 Caesar_Cipher
implicit none
integer, parameter :: key = 3
character(43) :: message = "The five boxing wizards jump quickly"
write(*, "(2a)") "Original message = ", message
call encrypt(message)
write(*, "(2a)") "Encrypted message = ", message
call decrypt(message)
write(*, "(2a)") "Decry... | #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 this program in C while keeping its functionality equivalent to the Fortran version. | program Caesar_Cipher
implicit none
integer, parameter :: key = 3
character(43) :: message = "The five boxing wizards jump quickly"
write(*, "(2a)") "Original message = ", message
call encrypt(message)
write(*, "(2a)") "Encrypted message = ", message
call decrypt(message)
write(*, "(2a)") "Decry... | #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 Go. | program Caesar_Cipher
implicit none
integer, parameter :: key = 3
character(43) :: message = "The five boxing wizards jump quickly"
write(*, "(2a)") "Original message = ", message
call encrypt(message)
write(*, "(2a)") "Encrypted message = ", message
call decrypt(message)
write(*, "(2a)") "Decry... | 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... |
Generate an equivalent Java version of this Fortran code. | program Caesar_Cipher
implicit none
integer, parameter :: key = 3
character(43) :: message = "The five boxing wizards jump quickly"
write(*, "(2a)") "Original message = ", message
call encrypt(message)
write(*, "(2a)") "Encrypted message = ", message
call decrypt(message)
write(*, "(2a)") "Decry... | 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... |
Change the following Fortran code into Python without altering its purpose. | program Caesar_Cipher
implicit none
integer, parameter :: key = 3
character(43) :: message = "The five boxing wizards jump quickly"
write(*, "(2a)") "Original message = ", message
call encrypt(message)
write(*, "(2a)") "Encrypted message = ", message
call decrypt(message)
write(*, "(2a)") "Decry... | 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 Fortran. | program Caesar_Cipher
implicit none
integer, parameter :: key = 3
character(43) :: message = "The five boxing wizards jump quickly"
write(*, "(2a)") "Original message = ", message
call encrypt(message)
write(*, "(2a)") "Encrypted message = ", message
call decrypt(message)
write(*, "(2a)") "Decry... | 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 PHP as shown in this Fortran implementation. | program Caesar_Cipher
implicit none
integer, parameter :: key = 3
character(43) :: message = "The five boxing wizards jump quickly"
write(*, "(2a)") "Original message = ", message
call encrypt(message)
write(*, "(2a)") "Encrypted message = ", message
call decrypt(message)
write(*, "(2a)") "Decry... | <?php
function caesarEncode( $message, $key ){
$plaintext = strtolower( $message );
$ciphertext = "";
$ascii_a = ord( 'a' );
$ascii_z = ord( 'z' );
while( strlen( $plaintext ) ){
$char = ord( $plaintext );
if( $char >= $ascii_a && $char <= $ascii_z ){
$char = ( ( $key + $... |
Rewrite the snippet below in C so it works the same as the original Groovy code. | def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
... | #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 a version of this Groovy function in C# with identical behavior. | def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
... | 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 a version of this Groovy function in C++ with identical behavior. | def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
... | #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"... |
Preserve the algorithm and functionality while converting the code from Groovy to Java. | def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
... | 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 Groovy implementation. | def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
... | 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 Groovy to VB with equivalent syntax and logic. | def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
... | 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,... |
Produce a language-to-language conversion: from Groovy to Go, same semantics. | def caesarEncode(cipherKey, text) {
def builder = new StringBuilder()
text.each { character ->
int ch = character[0] as char
switch(ch) {
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
}
... | 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 code in C as shown below in Haskell. | module Caesar (caesar, uncaesar) where
import Data.Char
caesar, uncaesar :: (Integral a) => a -> String -> String
caesar k = map f
where f c = case generalCategory c of
LowercaseLetter -> addChar 'a' k c
UppercaseLetter -> addChar 'A' k c
_ -> c
uncaesar k ... | #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... |
Transform the following Haskell implementation into C++, maintaining the same output and logic. | module Caesar (caesar, uncaesar) where
import Data.Char
caesar, uncaesar :: (Integral a) => a -> String -> String
caesar k = map f
where f c = case generalCategory c of
LowercaseLetter -> addChar 'a' k c
UppercaseLetter -> addChar 'A' k c
_ -> c
uncaesar k ... | #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 following Haskell code into Java without altering its purpose. | module Caesar (caesar, uncaesar) where
import Data.Char
caesar, uncaesar :: (Integral a) => a -> String -> String
caesar k = map f
where f c = case generalCategory c of
LowercaseLetter -> addChar 'a' k c
UppercaseLetter -> addChar 'A' k c
_ -> c
uncaesar k ... | 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 code in Python as shown below in Haskell. | module Caesar (caesar, uncaesar) where
import Data.Char
caesar, uncaesar :: (Integral a) => a -> String -> String
caesar k = map f
where f c = case generalCategory c of
LowercaseLetter -> addChar 'a' k c
UppercaseLetter -> addChar 'A' k c
_ -> c
uncaesar k ... | 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 Haskell snippet without changing its computational steps. | module Caesar (caesar, uncaesar) where
import Data.Char
caesar, uncaesar :: (Integral a) => a -> String -> String
caesar k = map f
where f c = case generalCategory c of
LowercaseLetter -> addChar 'a' k c
UppercaseLetter -> addChar 'A' k c
_ -> c
uncaesar k ... | 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 Haskell code into Go while preserving the original functionality. | module Caesar (caesar, uncaesar) where
import Data.Char
caesar, uncaesar :: (Integral a) => a -> String -> String
caesar k = map f
where f c = case generalCategory c of
LowercaseLetter -> addChar 'a' k c
UppercaseLetter -> addChar 'A' k c
_ -> c
uncaesar k ... | 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 following code from Icon to C with equivalent syntax and logic. | procedure main()
ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog"))
dtext := caesar(ctext,,"decrypt")
write("Plain text = ",image(ptext))
write("Encphered text = ",image(ctext))
write("Decphered text = ",image(dtext))
end
procedure caesar(text,k,mode)
/k := 3
k := (((k % *&lcase) + *&lca... | #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... |
Transform the following Icon implementation into C#, maintaining the same output and logic. | procedure main()
ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog"))
dtext := caesar(ctext,,"decrypt")
write("Plain text = ",image(ptext))
write("Encphered text = ",image(ctext))
write("Decphered text = ",image(dtext))
end
procedure caesar(text,k,mode)
/k := 3
k := (((k % *&lcase) + *&lca... | 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 functionally identical C++ code for the snippet given in Icon. | procedure main()
ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog"))
dtext := caesar(ctext,,"decrypt")
write("Plain text = ",image(ptext))
write("Encphered text = ",image(ctext))
write("Decphered text = ",image(dtext))
end
procedure caesar(text,k,mode)
/k := 3
k := (((k % *&lcase) + *&lca... | #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 Icon code. | procedure main()
ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog"))
dtext := caesar(ctext,,"decrypt")
write("Plain text = ",image(ptext))
write("Encphered text = ",image(ctext))
write("Decphered text = ",image(dtext))
end
procedure caesar(text,k,mode)
/k := 3
k := (((k % *&lcase) + *&lca... | 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 this program in Python while keeping its functionality equivalent to the Icon version. | procedure main()
ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog"))
dtext := caesar(ctext,,"decrypt")
write("Plain text = ",image(ptext))
write("Encphered text = ",image(ctext))
write("Decphered text = ",image(dtext))
end
procedure caesar(text,k,mode)
/k := 3
k := (((k % *&lcase) + *&lca... | 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 = ... |
Convert this Icon snippet to VB and keep its semantics consistent. | procedure main()
ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog"))
dtext := caesar(ctext,,"decrypt")
write("Plain text = ",image(ptext))
write("Encphered text = ",image(ctext))
write("Decphered text = ",image(dtext))
end
procedure caesar(text,k,mode)
/k := 3
k := (((k % *&lcase) + *&lca... | 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 Icon. | procedure main()
ctext := caesar(ptext := map("The quick brown fox jumped over the lazy dog"))
dtext := caesar(ctext,,"decrypt")
write("Plain text = ",image(ptext))
write("Encphered text = ",image(ctext))
write("Decphered text = ",image(dtext))
end
procedure caesar(text,k,mode)
/k := 3
k := (((k % *&lcase) + *&lca... | 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 J implementation. | cndx=: [: , 65 97 +/ 26 | (i.26)&+
caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
| #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 functionally identical C# code for the snippet given in J. | cndx=: [: , 65 97 +/ 26 | (i.26)&+
caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
| 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 following code from J to C++ with equivalent syntax and logic. | cndx=: [: , 65 97 +/ 26 | (i.26)&+
caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
| #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 J to Java with equivalent syntax and logic. | cndx=: [: , 65 97 +/ 26 | (i.26)&+
caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
| 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... |
Produce a language-to-language conversion: from J to Python, same semantics. | cndx=: [: , 65 97 +/ 26 | (i.26)&+
caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
| 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 J. | cndx=: [: , 65 97 +/ 26 | (i.26)&+
caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
| 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 J block to Go, preserving its control flow and logic. | cndx=: [: , 65 97 +/ 26 | (i.26)&+
caesar=: (cndx 0)}&a.@u:@cndx@[ {~ a.i.]
| 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 Julia. |
function csrcipher(text, key)
ciphtext = ""
for l in text
numl = Int(l)
ciphnuml = numl + key
if numl in 65:90
if ciphnuml > 90
rotciphnuml = ciphnuml - 26
ciphtext = ciphtext * Char(rotciphnuml)
else
ciphtext = ... | #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... |
Ensure the translated C# code behaves exactly like the original Julia snippet. |
function csrcipher(text, key)
ciphtext = ""
for l in text
numl = Int(l)
ciphnuml = numl + key
if numl in 65:90
if ciphnuml > 90
rotciphnuml = ciphnuml - 26
ciphtext = ciphtext * Char(rotciphnuml)
else
ciphtext = ... | 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 Julia snippet without changing its computational steps. |
function csrcipher(text, key)
ciphtext = ""
for l in text
numl = Int(l)
ciphnuml = numl + key
if numl in 65:90
if ciphnuml > 90
rotciphnuml = ciphnuml - 26
ciphtext = ciphtext * Char(rotciphnuml)
else
ciphtext = ... | #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 a Java translation of this Julia snippet without changing its computational steps. |
function csrcipher(text, key)
ciphtext = ""
for l in text
numl = Int(l)
ciphnuml = numl + key
if numl in 65:90
if ciphnuml > 90
rotciphnuml = ciphnuml - 26
ciphtext = ciphtext * Char(rotciphnuml)
else
ciphtext = ... | 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 Julia code in Python. |
function csrcipher(text, key)
ciphtext = ""
for l in text
numl = Int(l)
ciphnuml = numl + key
if numl in 65:90
if ciphnuml > 90
rotciphnuml = ciphnuml - 26
ciphtext = ciphtext * Char(rotciphnuml)
else
ciphtext = ... | 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 Julia code snippet into VB without altering its behavior. |
function csrcipher(text, key)
ciphtext = ""
for l in text
numl = Int(l)
ciphnuml = numl + key
if numl in 65:90
if ciphnuml > 90
rotciphnuml = ciphnuml - 26
ciphtext = ciphtext * Char(rotciphnuml)
else
ciphtext = ... | 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 Julia implementation. |
function csrcipher(text, key)
ciphtext = ""
for l in text
numl = Int(l)
ciphnuml = numl + key
if numl in 65:90
if ciphnuml > 90
rotciphnuml = ciphnuml - 26
ciphtext = ciphtext * Char(rotciphnuml)
else
ciphtext = ... | 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 Lua to C, same semantics. | 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... | #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 Lua to C#, same semantics. | 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... | 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 Lua. | 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... | #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 Lua to Java, same semantics. | 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... | 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 Lua snippet without changing its computational steps. | 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... | 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 = ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.