Last active
March 23, 2024 13:47
-
-
Save vianhanif/ac2387ba44dbf73896dce0e101aa409d to your computer and use it in GitHub Desktop.
Scytale Encryption & Decryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const column = 5 | |
export const encrypt = (text) => { | |
let token = text.split('') | |
let rows = token.length / column | |
let result = '' | |
for (let i = 0; i < column; i++) { | |
for (let j = 0; j < rows; j++) { | |
if ((j * column) + i < (token.length)) { | |
result = result + token[(j * column) + i] | |
} else { | |
result = result + '*' | |
} | |
} | |
} | |
return result | |
} | |
export const decrypt = (text) => { | |
let token = text.split('') | |
let rows = token.length / column | |
let result = '' | |
for (let j = 0; j < rows; j++) { | |
for (let i = 0; i < column; i++) { | |
if ((j * column) + i < (token.length)) { | |
result = result + token[(i * rows) + j] | |
} else { | |
result = result + '*' | |
} | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
D3X��F@��Q}V�P48�Q��[���pM`c�����
�A��أ�UB�\����A��AX$�H��H��=cHd����T��T1�4"��s��>S9��L�B(��ߎvUO�