我正在尝试加密/解密表单中的数据。我参加了帮助我这样做的课程:
https://github.com/o/crypt-php
加密有效,但是当我尝试解密时,它给出了一个错误说:
未捕获的异常'异常',消息'给定的数据似乎没有使用Crypt加密'
我的代码:
//for encrypt(this works)
require_once("Crypt.php");
$crypt = new Crypt;
$crypt->setKey('keykeykeyy');
$password = $_POST['password'];
$crypt->setData($password);
$encrypted = $crypt->encrypt();
//for decrypt almost the same thing
$password = $_POST['password'];
$crypt->setData($password);
$decrypted = $crypt->decrypt();
有什么问题?
答案 0 :(得分:1)
问题在于这一行
coins = [1, 6, 7, 4]
middle_length = len(coins) - 2
upper_limit = 2**middle_length
values = [0] * upper_limit
for cur_state in range(upper_limit - 1, 0, -1):
binary = bin(cur_state)[2:].zfill(middle_length)
for k, a in enumerate(binary):
if a == '1':
next_state = cur_state - 2**(middle_length - k - 1)
left_coin = k - (binary[:k][::-1] + '1').find('1')
right_coin = (binary[k + 1:] + '1').find('1') + k + 2
transit_value = (coins[left_coin] * coins[right_coin])
if values[cur_state] + transit_value > values[next_state]:
values[next_state] = values[cur_state] + transit_value
print(values[0])
您正在设置解密原始密码的数据 相反,你需要传递密码加密的数据
//for decrypt almost the same thing
$password = $_POST['password'];
$crypt->setData($password);
$decrypted = $crypt->decrypt();
问候