Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Change the following Lua code into C++ without altering its purpose. | #!/usr/bin/lua
local sha1 = require "sha1"
for i, str in ipairs{"Rosetta code", "Rosetta Code"} do
print(string.format("SHA-1(%q) = %s", str, sha1(str)))
end
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Rewrite this program in C++ while keeping its functionality equivalent to the Lua version. | #!/usr/bin/lua
local sha1 = require "sha1"
for i, str in ipairs{"Rosetta code", "Rosetta Code"} do
print(string.format("SHA-1(%q) = %s", str, sha1(str)))
end
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Keep all operations the same but rewrite the snippet in Python. | #!/usr/bin/lua
local sha1 = require "sha1"
for i, str in ipairs{"Rosetta code", "Rosetta Code"} do
print(string.format("SHA-1(%q) = %s", str, sha1(str)))
end
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Convert this Lua snippet to Python and keep its semantics consistent. | #!/usr/bin/lua
local sha1 = require "sha1"
for i, str in ipairs{"Rosetta code", "Rosetta Code"} do
print(string.format("SHA-1(%q) = %s", str, sha1(str)))
end
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Write a version of this Lua function in Go with identical behavior. | #!/usr/bin/lua
local sha1 = require "sha1"
for i, str in ipairs{"Rosetta code", "Rosetta Code"} do
print(string.format("SHA-1(%q) = %s", str, sha1(str)))
end
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Write the same algorithm in Go as shown in this Lua implementation. | #!/usr/bin/lua
local sha1 = require "sha1"
for i, str in ipairs{"Rosetta code", "Rosetta Code"} do
print(string.format("SHA-1(%q) = %s", str, sha1(str)))
end
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Can you help me rewrite this code in C instead of Nim, keeping it the same logically? | import std/sha1
echo secureHash("Rosetta Code")
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Convert the following code from Nim to C, ensuring the logic remains intact. | import std/sha1
echo secureHash("Rosetta Code")
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Write the same code in C# as shown below in Nim. | import std/sha1
echo secureHash("Rosetta Code")
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Please provide an equivalent version of this Nim code in C#. | import std/sha1
echo secureHash("Rosetta Code")
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Change the programming language of this snippet from Nim to C++ without modifying what it does. | import std/sha1
echo secureHash("Rosetta Code")
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Keep all operations the same but rewrite the snippet in C++. | import std/sha1
echo secureHash("Rosetta Code")
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Can you help me rewrite this code in Python instead of Nim, keeping it the same logically? | import std/sha1
echo secureHash("Rosetta Code")
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Preserve the algorithm and functionality while converting the code from Nim to Python. | import std/sha1
echo secureHash("Rosetta Code")
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Transform the following Nim implementation into Go, maintaining the same output and logic. | import std/sha1
echo secureHash("Rosetta Code")
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Produce a language-to-language conversion: from Nim to Go, same semantics. | import std/sha1
echo secureHash("Rosetta Code")
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Transform the following OCaml implementation into C, maintaining the same output and logic. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Write a version of this OCaml function in C with identical behavior. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Port the provided OCaml code into C# while preserving the original functionality. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Convert this OCaml block to C#, preserving its control flow and logic. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Convert this OCaml block to C++, preserving its control flow and logic. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Keep all operations the same but rewrite the snippet in C++. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Produce a functionally identical Python code for the snippet given in OCaml. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Please provide an equivalent version of this OCaml code in Python. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Write the same algorithm in Go as shown in this OCaml implementation. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Convert the following code from OCaml to Go, ensuring the logic remains intact. | $ ocaml -I +sha sha1.cma
Objective Caml version 3.12.1
# Sha1.to_hex (Sha1.string "Rosetta Code") ;;
- : string = "48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Convert the following code from Pascal to C, ensuring the logic remains intact. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Convert the following code from Pascal to C, ensuring the logic remains intact. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Produce a functionally identical C# code for the snippet given in Pascal. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Translate the given Pascal code snippet into C# without altering its behavior. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Rewrite the snippet below in C++ so it works the same as the original Pascal code. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Convert the following code from Pascal to C++, ensuring the logic remains intact. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Change the programming language of this snippet from Pascal to Python without modifying what it does. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Translate the given Pascal code snippet into Python without altering its behavior. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Port the provided Pascal code into Go while preserving the original functionality. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Ensure the translated Go code behaves exactly like the original Pascal snippet. | program RosettaSha1;
uses
sha1;
var
d: TSHA1Digest;
begin
d:=SHA1String('Rosetta Code');
WriteLn(SHA1Print(d));
end.
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Can you help me rewrite this code in C instead of Perl, keeping it the same logically? | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Convert the following code from Perl to C, ensuring the logic remains intact. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Generate a C# translation of this Perl snippet without changing its computational steps. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Generate a C# translation of this Perl snippet without changing its computational steps. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Write a version of this Perl function in C++ with identical behavior. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Maintain the same structure and functionality when rewriting this code in C++. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Port the provided Perl code into Python while preserving the original functionality. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Translate the given Perl code snippet into Python without altering its behavior. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Translate the given Perl code snippet into Go without altering its behavior. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Ensure the translated Go code behaves exactly like the original Perl snippet. | use Digest::SHA qw(sha1_hex);
print sha1_hex('Rosetta Code'), "\n";
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Produce a language-to-language conversion: from PowerShell to C, same semantics. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Change the following PowerShell code into C without altering its purpose. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Keep all operations the same but rewrite the snippet in C#. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Produce a language-to-language conversion: from PowerShell to C#, same semantics. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Please provide an equivalent version of this PowerShell code in C++. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Convert the following code from PowerShell to C++, ensuring the logic remains intact. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Can you help me rewrite this code in Python instead of PowerShell, keeping it the same logically? | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Write a version of this PowerShell function in Python with identical behavior. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Convert the following code from PowerShell to Go, ensuring the logic remains intact. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Write the same code in Go as shown below in PowerShell. | Function Calculate-SHA1( $String ){
$Enc = [system.Text.Encoding]::UTF8
$Data = $enc.GetBytes($String)
$Sha = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider
$Result = $sha.ComputeHash($Data)
[System.Convert]::ToBase64String($Result)
}
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Transform the following Racket implementation into C, maintaining the same output and logic. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Convert the following code from Racket to C, ensuring the logic remains intact. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Preserve the algorithm and functionality while converting the code from Racket to C#. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Translate this program into C# but keep the logic exactly as in Racket. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Change the following Racket code into C++ without altering its purpose. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Convert this Racket block to C++, preserving its control flow and logic. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Write the same code in Python as shown below in Racket. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Change the programming language of this snippet from Racket to Python without modifying what it does. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Write the same algorithm in Go as shown in this Racket implementation. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Convert the following code from Racket to Go, ensuring the logic remains intact. | #lang racket
(require file/sha1)
(sha1 (open-input-string "Rosetta Code"))
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Write the same code in C as shown below in REXX. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Port the following code from REXX to C with equivalent syntax and logic. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Generate an equivalent C# version of this REXX code. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Produce a language-to-language conversion: from REXX to C#, same semantics. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Convert this REXX snippet to C++ and keep its semantics consistent. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Transform the following REXX implementation into C++, maintaining the same output and logic. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Convert this REXX block to Python, preserving its control flow and logic. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Can you help me rewrite this code in Python instead of REXX, keeping it the same logically? |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Maintain the same structure and functionality when rewriting this code in Go. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Change the programming language of this snippet from REXX to Go without modifying what it does. |
options replace format comments java crossref savelog symbols binary
import java.security.MessageDigest
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method SHA1(messageText, verifyCheck) public static
algorithm = 'SHA-1'
digestSum = getDigest(messageText, algorithm)
say '<Message>'messageText'</Message>'
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
if digestSum == verifyCheck then say algorithm 'Confirmed'
else say algorithm 'Failed'
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
algorithm = algorithm.upper
encoding = encoding.upper
message = String(messageText)
messageBytes = byte[]
digestBytes = byte[]
digestSum = Rexx ''
do
messageBytes = message.getBytes(encoding)
md = MessageDigest.getInstance(algorithm)
md.update(messageBytes)
digestBytes = md.digest
loop b_ = 0 to digestBytes.length - 1
bb = Rexx(digestBytes[b_]).d2x(2)
if lowercase then digestSum = digestSum || bb.lower
else digestSum = digestSum || bb.upper
end b_
catch ex = Exception
ex.printStackTrace
end
return digestSum
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Rewrite the snippet below in C so it works the same as the original Ruby code. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Maintain the same structure and functionality when rewriting this code in C. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Translate this program into C# but keep the logic exactly as in Ruby. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Rewrite this program in C# while keeping its functionality equivalent to the Ruby version. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Port the following code from Ruby to C++ with equivalent syntax and logic. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Keep all operations the same but rewrite the snippet in C++. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Port the following code from Ruby to Python with equivalent syntax and logic. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Preserve the algorithm and functionality while converting the code from Ruby to Python. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Produce a language-to-language conversion: from Ruby to Go, same semantics. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Write a version of this Ruby function in Go with identical behavior. | require "openssl"
puts OpenSSL::Digest.new("sha1").update("Rosetta Code")
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Maintain the same structure and functionality when rewriting this code in C. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Generate an equivalent C version of this Scala code. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Generate a C# translation of this Scala snippet without changing its computational steps. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Convert this Scala block to C#, preserving its control flow and logic. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Port the provided Scala code into C++ while preserving the original functionality. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Generate an equivalent C++ version of this Scala code. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| #include <string>
#include <iostream>
#include "Poco/SHA1Engine.h"
#include "Poco/DigestStream.h"
using Poco::DigestEngine ;
using Poco::SHA1Engine ;
using Poco::DigestOutputStream ;
int main( ) {
std::string myphrase ( "Rosetta Code" ) ;
SHA1Engine sha1 ;
DigestOutputStream outstr( sha1 ) ;
outstr << myphrase ;
outstr.flush( ) ;
const DigestEngine::Digest& digest = sha1.digest( ) ;
std::cout << myphrase << " as a sha1 digest :" << DigestEngine::digestToHex( digest )
<< " !" << std::endl ;
return 0 ;
}
|
Generate a Python translation of this Scala snippet without changing its computational steps. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Port the following code from Scala to Python with equivalent syntax and logic. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| import crypto { sha1 }
let hash = sha1.hexdigest('Ars longa, vita brevis')
print hash
|
Rewrite this program in Go while keeping its functionality equivalent to the Scala version. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Port the provided Scala code into Go while preserving the original functionality. |
import java.security.MessageDigest
fun main(args: Array<String>) {
val text = "Rosetta Code"
val bytes = text.toByteArray()
val md = MessageDigest.getInstance("SHA-1")
val digest = md.digest(bytes)
for (byte in digest) print("%02x".format(byte))
println()
}
| package main
import (
"crypto/sha1"
"fmt"
)
func main() {
h := sha1.New()
h.Write([]byte("Rosetta Code"))
fmt.Printf("%x\n", h.Sum(nil))
}
|
Change the following Tcl code into C without altering its purpose. | package require sha1
puts [sha1::sha1 "Rosetta Code"]
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Can you help me rewrite this code in C instead of Tcl, keeping it the same logically? | package require sha1
puts [sha1::sha1 "Rosetta Code"]
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
int i;
unsigned char result[SHA_DIGEST_LENGTH];
const char *string = "Rosetta Code";
SHA1(string, strlen(string), result);
for(i = 0; i < SHA_DIGEST_LENGTH; i++)
printf("%02x%c", result[i], i < (SHA_DIGEST_LENGTH-1) ? ' ' : '\n');
return EXIT_SUCCESS;
}
|
Can you help me rewrite this code in C# instead of Tcl, keeping it the same logically? | package require sha1
puts [sha1::sha1 "Rosetta Code"]
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Write a version of this Tcl function in C# with identical behavior. | package require sha1
puts [sha1::sha1 "Rosetta Code"]
| using System;
using System.Security.Cryptography;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RosettaCode.SHA1
{
[TestClass]
public class SHA1CryptoServiceProviderTest
{
[TestMethod]
public void TestComputeHash()
{
var input = new UTF8Encoding().GetBytes("Rosetta Code");
var output = new SHA1CryptoServiceProvider().ComputeHash(input);
Assert.AreEqual(
"48-C9-8F-7E-5A-6E-73-6D-79-0A-B7-40-DF-C3-F5-1A-61-AB-E2-B5",
BitConverter.ToString(output));
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.