Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Keep all operations the same but rewrite the snippet in C++.
options replace format comments java crossref symbols nobinary import java.net. runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static parse arg host':'port':'message if host = '' then host = 'localhost' if port = '' ...
#include <boost/asio.hpp> int main() { boost::asio::io_context io_context; boost::asio::ip::tcp::socket sock(io_context); boost::asio::ip::tcp::resolver resolver(io_context); boost::asio::ip::tcp::resolver::query query("localhost", "4321"); boost::asio::connect(sock, resolver.resolve(query)); boost::asi...
Convert this REXX snippet to Java and keep its semantics consistent.
options replace format comments java crossref symbols nobinary import java.net. runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static parse arg host':'port':'message if host = '' then host = 'localhost' if port = '' ...
import java.io.IOException; import java.net.*; public class SocketSend { public static void main(String args[]) throws IOException { sendData("localhost", "hello socket world"); } public static void sendData(String host, String msg) throws IOException { Socket sock = new Socket( host, 256 ); sock.get...
Ensure the translated Python code behaves exactly like the original REXX snippet.
options replace format comments java crossref symbols nobinary import java.net. runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static parse arg host':'port':'message if host = '' then host = 'localhost' if port = '' ...
import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("localhost", 256)) sock.sendall("hello socket world") sock.close()
Transform the following REXX implementation into VB, maintaining the same output and logic.
options replace format comments java crossref symbols nobinary import java.net. runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static parse arg host':'port':'message if host = '' then host = 'localhost' if port = '' ...
Imports System Imports System.IO Imports System.Net.Sockets Public Class Program Public Shared Sub Main(ByVal args As String[]) Dim tcp As New TcpClient("localhost", 256) Dim writer As New StreamWriter(tcp.GetStream()) writer.Write("hello socket world") writer.Flush() tcp...
Write the same algorithm in Go as shown in this REXX implementation.
options replace format comments java crossref symbols nobinary import java.net. runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static parse arg host':'port':'message if host = '' then host = 'localhost' if port = '' ...
package main import ( "fmt" "net" ) func main() { conn, err := net.Dial("tcp", "localhost:256") if err != nil { fmt.Println(err) return } defer conn.Close() _, err = conn.Write([]byte("hello socket world")) if err != nil { fmt.Println(err) } }
Port the provided Ruby code into C while preserving the original functionality.
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> const char *msg = "hello socket world"; int main() { int i, sock, len, slen; struct addrinfo hints, *addrs; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_sockt...
Write the same algorithm in C# as shown in this Ruby implementation.
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
using System; using System.IO; using System.Net.Sockets; class Program { static void Main(string[] args) { TcpClient tcp = new TcpClient("localhost", 256); StreamWriter writer = new StreamWriter(tcp.GetStream()); writer.Write("hello socket world"); writer.Flush(); tcp.Clos...
Write the same code in C++ as shown below in Ruby.
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
#include <boost/asio.hpp> int main() { boost::asio::io_context io_context; boost::asio::ip::tcp::socket sock(io_context); boost::asio::ip::tcp::resolver resolver(io_context); boost::asio::ip::tcp::resolver::query query("localhost", "4321"); boost::asio::connect(sock, resolver.resolve(query)); boost::asi...
Port the provided Ruby code into Java while preserving the original functionality.
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
import java.io.IOException; import java.net.*; public class SocketSend { public static void main(String args[]) throws IOException { sendData("localhost", "hello socket world"); } public static void sendData(String host, String msg) throws IOException { Socket sock = new Socket( host, 256 ); sock.get...
Change the following Ruby code into Python without altering its purpose.
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("localhost", 256)) sock.sendall("hello socket world") sock.close()
Convert this Ruby snippet to VB and keep its semantics consistent.
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
Imports System Imports System.IO Imports System.Net.Sockets Public Class Program Public Shared Sub Main(ByVal args As String[]) Dim tcp As New TcpClient("localhost", 256) Dim writer As New StreamWriter(tcp.GetStream()) writer.Write("hello socket world") writer.Flush() tcp...
Port the following code from Ruby to Go with equivalent syntax and logic.
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
package main import ( "fmt" "net" ) func main() { conn, err := net.Dial("tcp", "localhost:256") if err != nil { fmt.Println(err) return } defer conn.Close() _, err = conn.Write([]byte("hello socket world")) if err != nil { fmt.Println(err) } }
Write the same algorithm in C as shown in this Scala implementation.
import java.net.Socket fun main(args: Array<String>) { val sock = Socket("localhost", 256) sock.use { it.outputStream.write("hello socket world".toByteArray()) } }
#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> const char *msg = "hello socket world"; int main() { int i, sock, len, slen; struct addrinfo hints, *addrs; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_sockt...
Preserve the algorithm and functionality while converting the code from Scala to C#.
import java.net.Socket fun main(args: Array<String>) { val sock = Socket("localhost", 256) sock.use { it.outputStream.write("hello socket world".toByteArray()) } }
using System; using System.IO; using System.Net.Sockets; class Program { static void Main(string[] args) { TcpClient tcp = new TcpClient("localhost", 256); StreamWriter writer = new StreamWriter(tcp.GetStream()); writer.Write("hello socket world"); writer.Flush(); tcp.Clos...
Port the provided Scala code into C++ while preserving the original functionality.
import java.net.Socket fun main(args: Array<String>) { val sock = Socket("localhost", 256) sock.use { it.outputStream.write("hello socket world".toByteArray()) } }
#include <boost/asio.hpp> int main() { boost::asio::io_context io_context; boost::asio::ip::tcp::socket sock(io_context); boost::asio::ip::tcp::resolver resolver(io_context); boost::asio::ip::tcp::resolver::query query("localhost", "4321"); boost::asio::connect(sock, resolver.resolve(query)); boost::asi...
Convert this Scala snippet to Java and keep its semantics consistent.
import java.net.Socket fun main(args: Array<String>) { val sock = Socket("localhost", 256) sock.use { it.outputStream.write("hello socket world".toByteArray()) } }
import java.io.IOException; import java.net.*; public class SocketSend { public static void main(String args[]) throws IOException { sendData("localhost", "hello socket world"); } public static void sendData(String host, String msg) throws IOException { Socket sock = new Socket( host, 256 ); sock.get...
Write a version of this Scala function in Python with identical behavior.
import java.net.Socket fun main(args: Array<String>) { val sock = Socket("localhost", 256) sock.use { it.outputStream.write("hello socket world".toByteArray()) } }
import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("localhost", 256)) sock.sendall("hello socket world") sock.close()
Change the programming language of this snippet from Scala to VB without modifying what it does.
import java.net.Socket fun main(args: Array<String>) { val sock = Socket("localhost", 256) sock.use { it.outputStream.write("hello socket world".toByteArray()) } }
Imports System Imports System.IO Imports System.Net.Sockets Public Class Program Public Shared Sub Main(ByVal args As String[]) Dim tcp As New TcpClient("localhost", 256) Dim writer As New StreamWriter(tcp.GetStream()) writer.Write("hello socket world") writer.Flush() tcp...
Transform the following Scala implementation into Go, maintaining the same output and logic.
import java.net.Socket fun main(args: Array<String>) { val sock = Socket("localhost", 256) sock.use { it.outputStream.write("hello socket world".toByteArray()) } }
package main import ( "fmt" "net" ) func main() { conn, err := net.Dial("tcp", "localhost:256") if err != nil { fmt.Println(err) return } defer conn.Close() _, err = conn.Write([]byte("hello socket world")) if err != nil { fmt.Println(err) } }
Port the following code from Tcl to C with equivalent syntax and logic.
set io [socket localhost 256] puts -nonewline $io "hello socket world" close $io
#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> const char *msg = "hello socket world"; int main() { int i, sock, len, slen; struct addrinfo hints, *addrs; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_sockt...
Rewrite the snippet below in C# so it works the same as the original Tcl code.
set io [socket localhost 256] puts -nonewline $io "hello socket world" close $io
using System; using System.IO; using System.Net.Sockets; class Program { static void Main(string[] args) { TcpClient tcp = new TcpClient("localhost", 256); StreamWriter writer = new StreamWriter(tcp.GetStream()); writer.Write("hello socket world"); writer.Flush(); tcp.Clos...
Can you help me rewrite this code in C++ instead of Tcl, keeping it the same logically?
set io [socket localhost 256] puts -nonewline $io "hello socket world" close $io
#include <boost/asio.hpp> int main() { boost::asio::io_context io_context; boost::asio::ip::tcp::socket sock(io_context); boost::asio::ip::tcp::resolver resolver(io_context); boost::asio::ip::tcp::resolver::query query("localhost", "4321"); boost::asio::connect(sock, resolver.resolve(query)); boost::asi...
Keep all operations the same but rewrite the snippet in Java.
set io [socket localhost 256] puts -nonewline $io "hello socket world" close $io
import java.io.IOException; import java.net.*; public class SocketSend { public static void main(String args[]) throws IOException { sendData("localhost", "hello socket world"); } public static void sendData(String host, String msg) throws IOException { Socket sock = new Socket( host, 256 ); sock.get...
Port the following code from Tcl to Python with equivalent syntax and logic.
set io [socket localhost 256] puts -nonewline $io "hello socket world" close $io
import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("localhost", 256)) sock.sendall("hello socket world") sock.close()
Transform the following Tcl implementation into VB, maintaining the same output and logic.
set io [socket localhost 256] puts -nonewline $io "hello socket world" close $io
Imports System Imports System.IO Imports System.Net.Sockets Public Class Program Public Shared Sub Main(ByVal args As String[]) Dim tcp As New TcpClient("localhost", 256) Dim writer As New StreamWriter(tcp.GetStream()) writer.Write("hello socket world") writer.Flush() tcp...
Convert this Tcl snippet to Go and keep its semantics consistent.
set io [socket localhost 256] puts -nonewline $io "hello socket world" close $io
package main import ( "fmt" "net" ) func main() { conn, err := net.Dial("tcp", "localhost:256") if err != nil { fmt.Println(err) return } defer conn.Close() _, err = conn.Write([]byte("hello socket world")) if err != nil { fmt.Println(err) } }
Write the same algorithm in PHP as shown in this Rust implementation.
use std::io::prelude::*; use std::net::TcpStream; fn main() { let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap(); let _ = my_stream.write(b"hello socket world"); }
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Write the same algorithm in PHP as shown in this Ada implementation.
with GNAT.Sockets; use GNAT.Sockets; procedure Socket_Send is Client : Socket_Type; begin Initialize; Create_Socket (Socket => Client); Connect_Socket (Socket => Client, Server => (Family => Family_Inet, Addr => Inet_Addr ("127.0.0.1"), ...
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Generate an equivalent PHP version of this AutoHotKey code.
Network_Port = 256 Network_Address = 127.0.0.1 NewData := false DataReceived = GoSub, Connection_Init SendData(socket,"hello socket world") return Connection_Init: OnExit, ExitSub socket := ConnectToAddress(Network_Address, Network_Port) if socket = -1 ExitApp Process, Exist DetectHiddenWindows On ScriptMainWind...
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Convert this AWK snippet to PHP and keep its semantics consistent.
BEGIN { s="/inet/tcp/256/0/0" print strftime() |& s close(s) }
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Keep all operations the same but rewrite the snippet in PHP.
INSTALL @lib$+"SOCKLIB" PROC_initsockets socket% = FN_tcpconnect("localhost", "256") IF socket% <=0 ERROR 100, "Failed to open socket" msg$ = "hello socket world" SYS `send`, socket%, !^msg$, LEN(msg$), 0 TO result% PROC_closesocket(socket%) PR...
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Please provide an equivalent version of this Clojure code in PHP.
(ns socket-example (:import (java.net Socket) (java.io PrintWriter))) (defn send-data [host msg] (with-open [sock (Socket. host 256) printer (PrintWriter. (.getOutputStream sock))] (.println printer msg))) (send-data "localhost" "hello socket world")
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Convert the following code from Common_Lisp to PHP, ensuring the logic remains intact.
CL-USER> (usocket:with-client-socket (socket stream "localhost" 256) (write-line "hello socket world" stream) (values))
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Translate this program into PHP but keep the logic exactly as in D.
module socket ; import std.stdio ; import std.socket ; version(Win32) { pragma(lib, "ws2_32.lib") ; } void main() { long res; auto socket = new Socket(AddressFamily.INET, SocketType.STREAM) ; socket.connect(new InternetAddress("localhost",256)) ; res = socket.send(cast(void[])"hello socket world") ; wri...
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Write a version of this Delphi function in PHP with identical behavior.
program Sockets; uses IdTCPClient; var lTCPClient: TIdTCPClient; begin lTCPClient := TIdTCPClient.Create(nil); try lTCPClient.Host := '127.0.0.1'; lTCPClient.Port := 256; lTCPClient.Connect; lTCPClient.IOHandler.WriteLn('hello socket world'); finally lTCPClient.Free; end; end.
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Convert this Elixir snippet to PHP and keep its semantics consistent.
defmodule Sockets do require Logger def send_message(port, message) do {:ok, socket} = :gen_tcp.connect('localhost', port, []) :gen_tcp.send(socket, message) end end Sockets.send_message(256, "hello socket world")
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Port the provided Erlang code into PHP while preserving the original functionality.
-module(socket). -export([start/0]). start() -> {ok, Sock} = gen_tcp:connect("localhost", 256, [binary, {packet, 0}]), ok = gen_tcp:send(Sock, "hello socket world"), ok = gen_tcp:close(Sock).
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Preserve the algorithm and functionality while converting the code from Factor to PHP.
"localhost" 256 <inet> utf8 [ "hello socket world" print ] with-client
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Port the provided Forth code into PHP while preserving the original functionality.
include unix/socket.fs s" localhost" 256 open-socket dup s" hello socket world" rot write-socket close-socket
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Preserve the algorithm and functionality while converting the code from Groovy to PHP.
s = new java.net.Socket("localhost", 256) s << "hello socket world" s.close()
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Port the provided Haskell code into PHP while preserving the original functionality.
import Network main = withSocketsDo $ sendTo "localhost" (PortNumber $ toEnum 256) "hello socket world"
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Port the provided Icon code into PHP while preserving the original functionality.
link cfunc procedure main () hello("localhost", 1024) end procedure hello (host, port) write(tconnect(host, port) | stop("unable to connect to", host, ":", port) , "hello socket world") end
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Please provide an equivalent version of this J code in PHP.
coinsert'jsocket' [ require 'socket' socket =. >{.sdcheck sdsocket'' host =. sdcheck sdgethostbyname 'localhost' sdcheck sdconnect socket ; host ,< 256 sdcheck 'hello socket world' sdsend socket , 0
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Write a version of this Julia function in PHP with identical behavior.
socket = connect("localhost",256) write(socket, "hello socket world") close(socket)
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Produce a language-to-language conversion: from Lua to PHP, same semantics.
socket = require "socket" host, port = "127.0.0.1", 256 sid = socket.udp() sid:sendto( "hello socket world", host, port ) sid:close()
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Write the same algorithm in PHP as shown in this Mathematica implementation.
socket = SocketConnect["localhost:256", "TCP"]; WriteString[socket, "hello socket world"]; Close[socket];
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Port the following code from Nim to PHP with equivalent syntax and logic.
import net var s = newSocket() s.connect("localhost", Port(256)) s.send("Hello Socket World") s.close()
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Keep all operations the same but rewrite the snippet in PHP.
open Unix let init_socket addr port = let inet_addr = (gethostbyname addr).h_addr_list.(0) in let sockaddr = ADDR_INET (inet_addr, port) in let sock = socket PF_INET SOCK_STREAM 0 in connect sock sockaddr; let outchan = out_channel_of_descr sock in let inchan = in_channel_of_descr sock in (inchan, out...
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Rewrite this program in PHP while keeping its functionality equivalent to the Pascal version.
Program Sockets_ExampleA; Uses sockets; Var TCP_Sock: integer; Remote_Addr: TSockAddr; Message: string; PMessage: Pchar; Message_Len: integer; Begin With Remote_Addr do begin Sin_family := AF_INET; Sin_addr := StrToNetAddr('127.0.0.1'); Sin_port := HtoNs(256); end;...
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Change the following Perl code into PHP without altering its purpose.
use Socket; $host = gethostbyname('localhost'); $in = sockaddr_in(256, $host); $proto = getprotobyname('tcp'); socket(Socket_Handle, AF_INET, SOCK_STREAM, $proto); connect(Socket_Handle, $in); send(Socket_Handle, 'hello socket world', 0, $in); close(Socket_Handle);
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Write the same code in PHP as shown below in Racket.
#lang racket (let-values ([(in out) (tcp-connect "localhost" 256)]) (display "hello socket world\n" out) (close-output-port out))
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Ensure the translated PHP code behaves exactly like the original REXX snippet.
options replace format comments java crossref symbols nobinary import java.net. runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) private static parse arg host':'port':'message if host = '' then host = 'localhost' if port = '' ...
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Write the same code in PHP as shown below in Ruby.
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Generate a PHP translation of this Scala snippet without changing its computational steps.
import java.net.Socket fun main(args: Array<String>) { val sock = Socket("localhost", 256) sock.use { it.outputStream.write("hello socket world".toByteArray()) } }
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Produce a functionally identical PHP code for the snippet given in Tcl.
set io [socket localhost 256] puts -nonewline $io "hello socket world" close $io
$socket = fsockopen('localhost', 256); fputs($socket, 'hello socket world'); fclose($socket);
Produce a language-to-language conversion: from C to Rust, same semantics.
#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> const char *msg = "hello socket world"; int main() { int i, sock, len, slen; struct addrinfo hints, *addrs; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_sockt...
use std::io::prelude::*; use std::net::TcpStream; fn main() { let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap(); let _ = my_stream.write(b"hello socket world"); }
Generate an equivalent Rust version of this C++ code.
#include <boost/asio.hpp> int main() { boost::asio::io_context io_context; boost::asio::ip::tcp::socket sock(io_context); boost::asio::ip::tcp::resolver resolver(io_context); boost::asio::ip::tcp::resolver::query query("localhost", "4321"); boost::asio::connect(sock, resolver.resolve(query)); boost::asi...
use std::io::prelude::*; use std::net::TcpStream; fn main() { let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap(); let _ = my_stream.write(b"hello socket world"); }
Convert the following code from C# to Rust, ensuring the logic remains intact.
using System; using System.IO; using System.Net.Sockets; class Program { static void Main(string[] args) { TcpClient tcp = new TcpClient("localhost", 256); StreamWriter writer = new StreamWriter(tcp.GetStream()); writer.Write("hello socket world"); writer.Flush(); tcp.Clos...
use std::io::prelude::*; use std::net::TcpStream; fn main() { let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap(); let _ = my_stream.write(b"hello socket world"); }
Convert this Java block to Rust, preserving its control flow and logic.
import java.io.IOException; import java.net.*; public class SocketSend { public static void main(String args[]) throws IOException { sendData("localhost", "hello socket world"); } public static void sendData(String host, String msg) throws IOException { Socket sock = new Socket( host, 256 ); sock.get...
use std::io::prelude::*; use std::net::TcpStream; fn main() { let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap(); let _ = my_stream.write(b"hello socket world"); }
Change the following Rust code into VB without altering its purpose.
use std::io::prelude::*; use std::net::TcpStream; fn main() { let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap(); let _ = my_stream.write(b"hello socket world"); }
Imports System Imports System.IO Imports System.Net.Sockets Public Class Program Public Shared Sub Main(ByVal args As String[]) Dim tcp As New TcpClient("localhost", 256) Dim writer As New StreamWriter(tcp.GetStream()) writer.Write("hello socket world") writer.Flush() tcp...
Translate the given Go code snippet into Rust without altering its behavior.
package main import ( "fmt" "net" ) func main() { conn, err := net.Dial("tcp", "localhost:256") if err != nil { fmt.Println(err) return } defer conn.Close() _, err = conn.Write([]byte("hello socket world")) if err != nil { fmt.Println(err) } }
use std::io::prelude::*; use std::net::TcpStream; fn main() { let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap(); let _ = my_stream.write(b"hello socket world"); }
Translate this program into Python but keep the logic exactly as in Rust.
use std::io::prelude::*; use std::net::TcpStream; fn main() { let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap(); let _ = my_stream.write(b"hello socket world"); }
import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("localhost", 256)) sock.sendall("hello socket world") sock.close()
Port the provided Ada code into C# while preserving the original functionality.
with Ada.Text_IO; procedure Caesar is type modulo26 is modulo 26; function modulo26 (Character: Character; Output: Character) return modulo26 is begin return modulo26 (Character'Pos(Character)+Character'Pos(Output)); end modulo26; function Character(Val: in modulo26; Output: Character) ...
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 Ada code into C while preserving the original functionality.
with Ada.Text_IO; procedure Caesar is type modulo26 is modulo 26; function modulo26 (Character: Character; Output: Character) return modulo26 is begin return modulo26 (Character'Pos(Character)+Character'Pos(Output)); end modulo26; function Character(Val: in modulo26; Output: Character) ...
#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 an equivalent C++ version of this Ada code.
with Ada.Text_IO; procedure Caesar is type modulo26 is modulo 26; function modulo26 (Character: Character; Output: Character) return modulo26 is begin return modulo26 (Character'Pos(Character)+Character'Pos(Output)); end modulo26; function Character(Val: in modulo26; Output: Character) ...
#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 Go code behaves exactly like the original Ada snippet.
with Ada.Text_IO; procedure Caesar is type modulo26 is modulo 26; function modulo26 (Character: Character; Output: Character) return modulo26 is begin return modulo26 (Character'Pos(Character)+Character'Pos(Output)); end modulo26; function Character(Val: in modulo26; Output: Character) ...
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 Java so it works the same as the original Ada code.
with Ada.Text_IO; procedure Caesar is type modulo26 is modulo 26; function modulo26 (Character: Character; Output: Character) return modulo26 is begin return modulo26 (Character'Pos(Character)+Character'Pos(Output)); end modulo26; function Character(Val: in modulo26; Output: Character) ...
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.
with Ada.Text_IO; procedure Caesar is type modulo26 is modulo 26; function modulo26 (Character: Character; Output: Character) return modulo26 is begin return modulo26 (Character'Pos(Character)+Character'Pos(Output)); end modulo26; function Character(Val: in modulo26; Output: Character) ...
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 the following code from Ada to VB, ensuring the logic remains intact.
with Ada.Text_IO; procedure Caesar is type modulo26 is modulo 26; function modulo26 (Character: Character; Output: Character) return modulo26 is begin return modulo26 (Character'Pos(Character)+Character'Pos(Output)); end modulo26; function Character(Val: in modulo26; Output: Character) ...
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 C.
ia: to :integer `a` iA: to :integer `A` lowAZ: `a`..`z` uppAZ: `A`..`Z` caesar: function [s, xx][ k: (not? null? attr 'decode)? -> 26-xx -> xx result: new "" loop s 'i [ (in? i lowAZ)? -> 'result ++ to :char ia + (k + (to :integer i) - ia) % 26 [ (in? i uppAZ)? -> 'result ++ to ...
#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...
Change the programming language of this snippet from Arturo to C# without modifying what it does.
ia: to :integer `a` iA: to :integer `A` lowAZ: `a`..`z` uppAZ: `A`..`Z` caesar: function [s, xx][ k: (not? null? attr 'decode)? -> 26-xx -> xx result: new "" loop s 'i [ (in? i lowAZ)? -> 'result ++ to :char ia + (k + (to :integer i) - ia) % 26 [ (in? i uppAZ)? -> 'result ++ to ...
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 Arturo function in C++ with identical behavior.
ia: to :integer `a` iA: to :integer `A` lowAZ: `a`..`z` uppAZ: `A`..`Z` caesar: function [s, xx][ k: (not? null? attr 'decode)? -> 26-xx -> xx result: new "" loop s 'i [ (in? i lowAZ)? -> 'result ++ to :char ia + (k + (to :integer i) - ia) % 26 [ (in? i uppAZ)? -> 'result ++ to ...
#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 Arturo code into Java without altering its purpose.
ia: to :integer `a` iA: to :integer `A` lowAZ: `a`..`z` uppAZ: `A`..`Z` caesar: function [s, xx][ k: (not? null? attr 'decode)? -> 26-xx -> xx result: new "" loop s 'i [ (in? i lowAZ)? -> 'result ++ to :char ia + (k + (to :integer i) - ia) % 26 [ (in? i uppAZ)? -> 'result ++ to ...
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.
ia: to :integer `a` iA: to :integer `A` lowAZ: `a`..`z` uppAZ: `A`..`Z` caesar: function [s, xx][ k: (not? null? attr 'decode)? -> 26-xx -> xx result: new "" loop s 'i [ (in? i lowAZ)? -> 'result ++ to :char ia + (k + (to :integer i) - ia) % 26 [ (in? i uppAZ)? -> 'result ++ to ...
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 programming language of this snippet from Arturo to VB without modifying what it does.
ia: to :integer `a` iA: to :integer `A` lowAZ: `a`..`z` uppAZ: `A`..`Z` caesar: function [s, xx][ k: (not? null? attr 'decode)? -> 26-xx -> xx result: new "" loop s 'i [ (in? i lowAZ)? -> 'result ++ to :char ia + (k + (to :integer i) - ia) % 26 [ (in? i uppAZ)? -> 'result ++ to ...
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 Arturo snippet.
ia: to :integer `a` iA: to :integer `A` lowAZ: `a`..`z` uppAZ: `A`..`Z` caesar: function [s, xx][ k: (not? null? attr 'decode)? -> 26-xx -> xx result: new "" loop s 'i [ (in? i lowAZ)? -> 'result ++ to :char ia + (k + (to :integer i) - ia) % 26 [ (in? i uppAZ)? -> 'result ++ to ...
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 the given AutoHotKey code snippet into C without altering its behavior.
n=2 s=HI t:=&s While *t o.=Chr(Mod(*t-65+n,26)+65),t+=2 MsgBox % o
#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 AutoHotKey block to C#, preserving its control flow and logic.
n=2 s=HI t:=&s While *t o.=Chr(Mod(*t-65+n,26)+65),t+=2 MsgBox % o
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 AutoHotKey code into C++ without altering its purpose.
n=2 s=HI t:=&s While *t o.=Chr(Mod(*t-65+n,26)+65),t+=2 MsgBox % o
#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 AutoHotKey to Java with equivalent syntax and logic.
n=2 s=HI t:=&s While *t o.=Chr(Mod(*t-65+n,26)+65),t+=2 MsgBox % o
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 AutoHotKey, keeping it the same logically?
n=2 s=HI t:=&s While *t o.=Chr(Mod(*t-65+n,26)+65),t+=2 MsgBox % o
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 AutoHotKey code.
n=2 s=HI t:=&s While *t o.=Chr(Mod(*t-65+n,26)+65),t+=2 MsgBox % o
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,...
Rewrite this program in Go while keeping its functionality equivalent to the AutoHotKey version.
n=2 s=HI t:=&s While *t o.=Chr(Mod(*t-65+n,26)+65),t+=2 MsgBox % o
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 AWK.
BEGIN { message = "My hovercraft is full of eels." key = 1 cypher = caesarEncode(key, message) clear = caesarDecode(key, cypher) print "message: " message print " cypher: " cypher print " clear: " clear exit } function caesarEncode(key, message) { return caesarXlat(key, messag...
#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 AWK to C#, ensuring the logic remains intact.
BEGIN { message = "My hovercraft is full of eels." key = 1 cypher = caesarEncode(key, message) clear = caesarDecode(key, cypher) print "message: " message print " cypher: " cypher print " clear: " clear exit } function caesarEncode(key, message) { return caesarXlat(key, messag...
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); } ...
Ensure the translated C++ code behaves exactly like the original AWK snippet.
BEGIN { message = "My hovercraft is full of eels." key = 1 cypher = caesarEncode(key, message) clear = caesarDecode(key, cypher) print "message: " message print " cypher: " cypher print " clear: " clear exit } function caesarEncode(key, message) { return caesarXlat(key, messag...
#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 functionally identical Java code for the snippet given in AWK.
BEGIN { message = "My hovercraft is full of eels." key = 1 cypher = caesarEncode(key, message) clear = caesarDecode(key, cypher) print "message: " message print " cypher: " cypher print " clear: " clear exit } function caesarEncode(key, message) { return caesarXlat(key, messag...
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 AWK to Python, same semantics.
BEGIN { message = "My hovercraft is full of eels." key = 1 cypher = caesarEncode(key, message) clear = caesarDecode(key, cypher) print "message: " message print " cypher: " cypher print " clear: " clear exit } function caesarEncode(key, message) { return caesarXlat(key, messag...
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 AWK code into VB while preserving the original functionality.
BEGIN { message = "My hovercraft is full of eels." key = 1 cypher = caesarEncode(key, message) clear = caesarDecode(key, cypher) print "message: " message print " cypher: " cypher print " clear: " clear exit } function caesarEncode(key, message) { return caesarXlat(key, messag...
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,...
Preserve the algorithm and functionality while converting the code from AWK to Go.
BEGIN { message = "My hovercraft is full of eels." key = 1 cypher = caesarEncode(key, message) clear = caesarDecode(key, cypher) print "message: " message print " cypher: " cypher print " clear: " clear exit } function caesarEncode(key, message) { return caesarXlat(key, messag...
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 BBC_Basic implementation into C, maintaining the same output and logic.
plaintext$ = "Pack my box with five dozen liquor jugs" PRINT plaintext$ key% = RND(25) cyphertext$ = FNcaesar(plaintext$, key%) PRINT cyphertext$ decyphered$ = FNcaesar(cyphertext$, 26-key%) PRINT decyphered$ END DEF FNcaesar(text$, 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...
Ensure the translated C# code behaves exactly like the original BBC_Basic snippet.
plaintext$ = "Pack my box with five dozen liquor jugs" PRINT plaintext$ key% = RND(25) cyphertext$ = FNcaesar(plaintext$, key%) PRINT cyphertext$ decyphered$ = FNcaesar(cyphertext$, 26-key%) PRINT decyphered$ END DEF FNcaesar(text$, 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 BBC_Basic to C++ with equivalent syntax and logic.
plaintext$ = "Pack my box with five dozen liquor jugs" PRINT plaintext$ key% = RND(25) cyphertext$ = FNcaesar(plaintext$, key%) PRINT cyphertext$ decyphered$ = FNcaesar(cyphertext$, 26-key%) PRINT decyphered$ END DEF FNcaesar(text$, 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 BBC_Basic version.
plaintext$ = "Pack my box with five dozen liquor jugs" PRINT plaintext$ key% = RND(25) cyphertext$ = FNcaesar(plaintext$, key%) PRINT cyphertext$ decyphered$ = FNcaesar(cyphertext$, 26-key%) PRINT decyphered$ END DEF FNcaesar(text$, 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...
Write the same algorithm in Python as shown in this BBC_Basic implementation.
plaintext$ = "Pack my box with five dozen liquor jugs" PRINT plaintext$ key% = RND(25) cyphertext$ = FNcaesar(plaintext$, key%) PRINT cyphertext$ decyphered$ = FNcaesar(cyphertext$, 26-key%) PRINT decyphered$ END DEF FNcaesar(text$, 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 = ...
Please provide an equivalent version of this BBC_Basic code in VB.
plaintext$ = "Pack my box with five dozen liquor jugs" PRINT plaintext$ key% = RND(25) cyphertext$ = FNcaesar(plaintext$, key%) PRINT cyphertext$ decyphered$ = FNcaesar(cyphertext$, 26-key%) PRINT decyphered$ END DEF FNcaesar(text$, 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,...
Rewrite this program in Go while keeping its functionality equivalent to the BBC_Basic version.
plaintext$ = "Pack my box with five dozen liquor jugs" PRINT plaintext$ key% = RND(25) cyphertext$ = FNcaesar(plaintext$, key%) PRINT cyphertext$ decyphered$ = FNcaesar(cyphertext$, 26-key%) PRINT decyphered$ END DEF FNcaesar(text$, 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...
Write a version of this Clojure function in C 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...
#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 Clojure block to C#, preserving its control flow 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...
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); } ...
Ensure the translated C++ code behaves exactly like the original Clojure snippet.
(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...
#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"...