【问题标题】:XOR operand on two strings in python?python中两个字符串的XOR运算符?
【发布时间】:2015-11-04 22:01:13
【问题描述】:

我正在尝试在 python 中使用两个字符串进行 XOR 操作。

这是我的脚本:

packet = "277500011200".decode("hex")
xor = codecs.decode(xor, 'hex')

print packet ^ xor

xor 变量应该基本上是一个键,如果我将它们异或在一起,它们将解码数据包。但是,它告诉我它们都是字符串。如何将类型更改为十六进制,以便它们可以正常工作?

【问题讨论】:

    标签: python hex xor


    【解决方案1】:

    int("ff048deadbeef", 16) 从十六进制转换为整数。

    编辑:似乎 OP 打算在转换之前使用 x.decode(codec)

    【讨论】:

    • 我已经这样做了,但现在我得到了这个错误:invalid literal for int() with base 16:
    • invalid literal for int() with base 16: 什么?
    • 您能在此处粘贴导致该错误的特定字符串吗?
    • packet = "27750001120007023e12a4f67b12482fb389f8f4a575f4e686fe6305d892d5dda87045864462bf78cfb03f7ce511259a29997d9d7a994db56d13503e643f0dfb3d4e5c7b5b12f0296e26316ff2be4009dd9e935d1357fa49f1af49df7edd6594c2a62b0d786c6b3ccecf8619355b4710c3af163afcf2e6351de55ae9fdd80fae9855952edbd220958c4292582476e29adeb95a634008d6fdd966a147584d8e0646c6bb4292a6847577a1b4a7114848eb1d7b93a12f7a935e9277e14905f25a24677511922f2306973bda16d26f03c78efda934070a693e532d9e7e09d822597836b911a557d55e7d3540a1aa357938990c6fbeb81f63393c85bff1e50e9893b4db547152e4bedfb8ddbddb0ae1eb314c70608ead310db4cc6f".decode("hex")
    猜你喜欢
    • 2013-04-20
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 2011-07-04
    • 2011-07-21
    相关资源
    最近更新 更多