【熵密杯】两个数值异或脚本
2023-8-11 01:23:43 Author: 利刃信安攻防实验室(查看原文) 阅读量:9 收藏

两个数值异或脚本

#!/usr/bin/env python3# -*- coding: utf-8 -*-
def convert_to_decimal(number_str): if number_str.startswith("0b"): return int(number_str, 2) elif number_str.startswith("0o"): return int(number_str, 8) elif number_str.startswith("0x"): return int(number_str, 16) else: return int(number_str)
def format_output(decimal_value): binary = bin(decimal_value)[2:] octal = oct(decimal_value)[2:] hexadecimal = hex(decimal_value)[2:] return { "十进制 Decimal": decimal_value, "二进制 Binary": binary, "八进制 Octal": octal, "十六进制 Hexadecimal": hexadecimal }
def main(): input_1 = input("请输入第一个数值:") input_2 = input("请输入第二个数值:")
num_1 = convert_to_decimal(input_1) num_2 = convert_to_decimal(input_2)
result_decimal = num_1 ^ num_2 result_formatted = format_output(result_decimal)
print("\n异或结果:") for notation, value in result_formatted.items(): print(f"{notation}: {value}")
if __name__ == "__main__": main()
package main
import ( "fmt" "math/big" "strings")
func convertToDecimal(numberStr string) *big.Int { numberStr = strings.ToLower(numberStr) base := 10
if strings.HasPrefix(numberStr, "0b") { base = 2 numberStr = numberStr[2:] } else if strings.HasPrefix(numberStr, "0o") { base = 8 numberStr = numberStr[2:] } else if strings.HasPrefix(numberStr, "0x") { base = 16 numberStr = numberStr[2:] }
value := new(big.Int) value, _ = value.SetString(numberStr, base) return value}
func main() { var input1, input2 string fmt.Print("请输入第一个数值:") _, _ = fmt.Scan(&input1) fmt.Print("请输入第二个数值:") _, _ = fmt.Scan(&input2)
num1 := convertToDecimal(input1) num2 := convertToDecimal(input2)
result := new(big.Int).Xor(num1, num2)
fmt.Println("\n异或结果:") fmt.Printf("十进制 Decimal: %s\n", result.String()) fmt.Printf("二进制 Binary: %s\n", result.Text(2)) fmt.Printf("八进制 Octal: %s\n", result.Text(8)) fmt.Printf("十六进制 Hexadecimal: %s\n", result.Text(16))}

阅读 10万+


文章来源: http://mp.weixin.qq.com/s?__biz=MzU1Mjk3MDY1OA==&mid=2247506022&idx=1&sn=10f923ad887bb1b7ec3bce43e4aa0eec&chksm=fbfb68abcc8ce1bdf4ec44369bd6cc5b7c0e971d7bd38abbccee4e8d4c79837d072c82d33e7f&scene=0&xtrack=1#rd
如有侵权请联系:admin#unsafe.sh