Skip to content

Instantly share code, notes, and snippets.

@vianhanif
Last active March 23, 2024 13:47
Show Gist options
  • Save vianhanif/ac2387ba44dbf73896dce0e101aa409d to your computer and use it in GitHub Desktop.
Save vianhanif/ac2387ba44dbf73896dce0e101aa409d to your computer and use it in GitHub Desktop.
Scytale Encryption & Decryption
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
}
@Habib144
Copy link

D3X��F@��Q}V�P48�Q��[���pM`c�����
�A��أ�UB�\����A��AX$�H��H��=cHd����T��T1�4"��s��>S9��L�B(��ߎvUO�

�'��%fueE�d�B8^�Xr� ��X��e��4CWg@�@4��������FWH�A���D�1R�8�A+��<_<�2����(���

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment