0
저는 현재 단순한 시저 암호 해독을 구현하기 위해 바이트 단위의 오프셋을 시도하고 있습니다. 그러나, 나는 이것을하는 방법을 알아낼 수 없습니다.바이트 단위로 정수 단위로 바이트를 오프셋하는 방법은 무엇입니까?
그러나function decrypt(bytes32 data, int key) public returns (bool) {
bytes32 decryptedData = data; // `data` here is the encrypted data
// decryption
for (int i = 0; i < decryptedData.length; i++) {
decryptedData[i] = (decryptedData[i] - key) % 256;
}
// returns if sha256(decryptedData) matches some value
}
, 이것은 다음과 같은 오류가 나에게 제공합니다 :
TypeError: Expression has to be an lvalue.
decryptedData[i] = (decryptedData[i] - key) % 256;
^--------------^
TypeError: Operator - not compatible with types bytes1 and int256
decryptedData[i] = (decryptedData[i] - key) % 256;
^--------------------^
TypeError: Operator % not compatible with types bytes1 and int_const 256
decryptedData[i] = (decryptedData[i] - key) % 256;
^----------------------------^
감사합니다 여기에 리믹스에 몇 가지 컴파일러 오류를 제공 내 현재 코드입니다!
"색인 액세스"섹션을 참조하십시오. –
오른쪽, 키는 함수 매개 변수의 int로 정의됩니다! 나는 그것에 대해 미안한 것을 업데이트 할 것이다. – aevumcessi
따라서 제시된 알고리즘은 질문에서 제시된 것처럼 색인 개수만큼 바이트를 이동시키지 않으므로 시저 암호의 알고리즘이 아닙니다. –