标题: java大佬帮忙翻译成go或者php或者js代码
时间: 2023-01-07
public class Main {
public static void main(String[] args) throws NoSuchAlgorithmException {
Scanner scanner = new Scanner(System.in);
System.out.println("FinalShell-Keygen v1.0 - Developed by UltraPanda\n* Only for educational purpose *\n请输入离线激活所提供的机器码: ");
String hardwareId = scanner.nextLine();
System.out.printf("高级版激活码: %s\n专业版激活码: %s%n", transform('\uef79' + hardwareId + 8552), transform(2356 + hardwareId + 13593));
}
public static String transform(String str) throws NoSuchAlgorithmException {
return hashMD5(str).substring(8, 24);
}
public static String hashMD5(String str) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] hashed = digest.digest(str.getBytes());
StringBuilder sb = new StringBuilder();
byte[] var4 = hashed;
int var5 = hashed.length;
for(int var6 = 0; var6 < var5; ++var6) {
byte b = var4[var6];
int len = b & 255;
if (len < 16) {
sb.append("0");
}
sb.append(Integer.toHexString(len));
}
return sb.toString();
}
}
『回复列表(20|显示机器人聊天)』
package main
import (
"crypto/md5"
"fmt"
)
func main() {
var hardwareId string
fmt.Println("FinalShell-Keygen v1.0 - Developed by UltraPanda\n* Only for educational purpose *\n请输入离线激活所提供的机器码: ")
fmt.Scanf("%s", &hardwareId)
fmt.Println("高级版激活码: ", transform("?"+hardwareId+"8552"), "\n专业版激活码: ", transform("2356"+hardwareId+"13593"))
}
func transform(str string) string {
return hashMD5(str)[8:24]
}
func hashMD5(str string) string {
return fmt.Sprintf("%x", md5.Sum([]byte(str)))
}
虽然不太懂JAVA,但是原代码应该是有问题的,\uef79
+hardwareId后,string的第一个字节居然是3f
,所以虽然不知道为什么,但是在转成golang的时候只需要拼接?
就行了
红米K30 Pro(变焦版)
<!DOCTYPE html>
<html>
<head>
<title>FinalShell Keygen</title>
</head>
<body>
<h1>FinalShell-Keygen v1.0 - Developed by UltraPanda</h1>
<p>* Only for educational purpose *</p>
<?php
if (isset($_POST['hardwareId'])) {
$hardwareId = $_POST['hardwareId'];
$advancedCode = transform('\uef79' . $hardwareId . 8552);
$professionalCode = transform(2356 . $hardwareId . 13593);
?>
<p>高级版激活码: <?php echo $advancedCode ?></p>
<p>专业版激活码: <?php echo $professionalCode ?></p>
<?php
} else {
?>
<p>请输入离线激活所提供的机器码:</p>
<form action="" method="post">
<input name="hardwareId" type="text" />
<input type="submit" value="生成激活码" />
</form>
<?php
}
?>
</body>
</html>
<?php
function transform($str) {
return hashMD5($str).substr(8, 16);
}
function hashMD5($str) {
return md5($str);
}
?>
chatgpt给出的PHP版本
ChatGPT给出的结果确实很惊艳:
而且不清楚它是不是知道我喜欢php-cli,所以给了我cli版的代码。
<?php
function transform($str) {
return substr(hashMD5($str), 8, 24);
}
function hashMD5($str) {
return hash("md5", $str);
}
echo "FinalShell-Keygen v1.0 - Developed by UltraPanda\n* Only for educational purpose *\n请输入离线激活所提供的机器码: ";
$handle = fopen ("php://stdin","r");
$hardwareId = fgets($handle);
echo "高级版激活码: " . transform("\uef79" . $hardwareId . 8552) . "\n";
echo "专业版激活码: " . transform(2356 . $hardwareId . 13593) . "\n";
?>
只是可惜它给的结果是错误的,与java版结果并不一致。旧人的那个回答结果也不正确(还是语法错误:hashMD5($str).substr(8, 16)
)。
不过我的回答犯的三个错误都比较容易修复:
\u
转义,需要使用特殊字符本身,或者其他方式表达。不过它还能做这种操作,方便我测试了:
加上 import 后代码应该长这样:
import java.util.Scanner;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Main {
public static void main(String[] args) throws NoSuchAlgorithmException {
Scanner scanner = new Scanner(System.in);
System.out.println("FinalShell-Keygen v1.0 - Developed by UltraPanda\n* Only for educational purpose *\n请输入离线激活所提供的机器码: ");
String hardwareId = scanner.nextLine();
System.out.printf("高级版激活码: %s\n专业版激活码: %s%n", transform('\uef79' + hardwareId + 8552), transform(2356 + hardwareId + 13593));
}
public static String transform(String str) throws NoSuchAlgorithmException {
return hashMD5(str).substring(8, 24);
}
public static String hashMD5(String str) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] hashed = digest.digest(str.getBytes());
StringBuilder sb = new StringBuilder();
byte[] var4 = hashed;
int var5 = hashed.length;
for(int var6 = 0; var6 < var5; ++var6) {
byte b = var4[var6];
int len = b & 255;
if (len < 16) {
sb.append("0");
}
sb.append(Integer.toHexString(len));
}
return sb.toString();
}
}
至于golang,在经我两次提醒之后,ChatGPT给出了完全正确的结果:
package main
import (
"bufio"
"fmt"
"crypto/md5"
"os"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Println("FinalShell-Keygen v1.0 - Developed by UltraPanda\n* Only for educational purpose *\n请输入离线激活所提供的机器码: ")
hardwareId, _ := reader.ReadString('\n')
hardwareId = strings.TrimSpace(hardwareId)
fmt.Printf("高级版激活码: %s\n专业版激活码: %s\n", transform("\U0000ef79" + hardwareId + "8552"), transform("2356" + hardwareId + "13593"))
}
func transform(str string) string {
return hashMD5(str)[8:24]
}
func hashMD5(str string) string {
hashed := md5.Sum([]byte(str))
sb := ""
for _, b := range hashed {
len := int(b) & 255
if len < 16 {
sb += "0"
}
sb += fmt.Sprintf("%x", len)
}
return sb
}
继续PHP:
这个回答其实很不错,我没告诉它要修复trim,它也修复了。
最后它真的修好了,结果完全正确。
<?php
echo "FinalShell-Keygen v1.0 - Developed by UltraPanda\n* Only for educational purpose *\n请输入离线激活所提供的机器码: ";
$hardwareId = trim(fgets(STDIN));
echo "高级版激活码: " . transform("\u{ef79}" . $hardwareId . "8552") . "\n";
echo "专业版激活码: " . transform("2356" . $hardwareId . "13593") . "\n";
function transform($str) {
return substr(hashMD5($str), 8, 16);
}
function hashMD5($str) {
return md5($str);
}
@艾木友尔尔巴,官网:https://chat.openai.com/ 需要自己想办法获取访问资格。
前几天别人建的免登录反向代理 https://gpt.chatapi.art 现在已经用不了了。