//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. Function encode(string memory key, string memory plaintext) public pure returns (string memory) { uint keyLength = bytes(key).length; uint plainLength = bytes(plaintext).length; uint numCols = (plainLength + keyLength - 1) / keyLength; uint[] memory order = new uint[](keyLength); for (uint i = 0; i < keyLength; i++) { order[i] = i; } string memory ciphertext = ""; for (uint num = 0; num < numCols; num++) { for (uint i = 0; i < keyLength; i++) { if (num * keyLength + order[i] < plainLength) { ciphertext = string(abi.encodePacked(ciphertext, bytes(plaintext)[num * keyLength + order[i]])); } } } return ciphertext; } // Example usage encode("KEY", "HELLO");
0.4.18