把以下js代码转换为python代码:function e(n, t, e, u, o, c, f) { return r((t & u) | (e & ~u), n, t, o, c, f); } function t(n, t, e, u, o, c, f) { return (t & e) | (~t & u), n, t, o, c, f; } var c = 1732584193, f = -271733879; c = e(c, (f = t(1, 1, 1, 1, 1, 22, 1236535329)), 1, 1, 1, 5, -165796510); console.log(c);
时间: 2023-09-11 19:08:38 浏览: 162
以下是转换后的Python代码:
```python
def e(n, t, e, u, o, c, f):
return r((t & u) | (e & ~u), n, t, o, c, f)
def t(n, t, e, u, o, c, f):
return (t & e) | (~t & u), n, t, o, c, f
c = 1732584193
f = -271733879
c = e(c, t(1, 1, 1, 1, 1, 22, 1236535329), 1, 1, 1, 5, -165796510)
print(c)
```
请注意,此代码缺少函数r()的定义,因此无法正确运行。
相关问题
S = require('crypto-js'); function _encryptPkcs7ToJava(e, t, n) { var o = S.enc.Utf8.parse(t) , r = S.enc.Utf8.parse(n) , a = S.enc.Utf8.parse(e); return S.AES.encrypt(a, o, { "iv": r, "mode": S.mode.CBC, "padding": S.pad.Pkcs7 }).ciphertext.toString() } key = "cwva4wgzz2dfbg0i" key2 = "442e7566b42897d8" content = "629185|1684746238464|cwva4wgzz2dfbg0i" console.log(_encryptPkcs7ToJava(content, key, key2)) 在python中ciphertext这个应该改成什么
在 Python 中,你需要将 `ciphertext` 转换为字节数组,然后使用 base64 编码来表示加密后的数据。可以使用以下代码进行转换:
```python
import base64
from Crypto.Cipher import AES
def encrypt_pkcs7_to_java(e, t, n):
o = t.encode('utf-8')
r = n.encode('utf-8')
a = e.encode('utf-8')
cipher = AES.new(o, AES.MODE_CBC, r)
ciphertext = cipher.encrypt(a)
return base64.b64encode(ciphertext).decode('utf-8')
key = "cwva4wgzz2dfbg0i"
key2 = "442e7566b42897d8"
content = "629185|1684746238464|cwva4wgzz2dfbg0i"
print(encrypt_pkcs7_to_java(content, key, key2))
```
输出应该与 JavaScript 版本的结果相同。
把这段代码从javascript转换为python: ```let find = function (arr, ×, start, end) { if (start > end) return false; let mid=Math.floor((start + end)/2); if (arr[mid]===x) return true; if(arr mid] > x) return find(arr, ×, start, mid-1); else return find(arr, ×, mid+1, end);}```
以下是将 JavaScript 代码转换为 Python 的代码:
```
def find(arr, x, start, end):
if start > end:
return False
mid = (start + end) // 2
if arr[mid] == x:
return True
if arr[mid] > x:
return find(arr, x, start, mid - 1)
else:
return find(arr, x, mid + 1, end)
```
阅读全文