Skip to content

Instantly share code, notes, and snippets.

@hueitan

hueitan/encrypt.md

Last active Aug 29, 2015
Embed
What would you like to do?
function arr_encryption(msg) {
  var message = msg.split(' ').join('.'),
      output = '';
      
  // add . if needed
  for (k=0;k<message.length % 6;k++) {
    message += '.';
  }
  
  // [Attack.at.noon] => change
  for (j=0;j<6;j++) {
  	for (i=j;i<message.length;i+=6) {
      output += message[i];
  	}
    if (j<5)output += ' ';
  }
  return output;
}

105 char

m = arguments[j=0]
  
while(m.length %6) m += O=o=' '

for (;j<6;O += o)
  for (i=j++;d=m[i];i+=6) 
    O += d == o ? '.' : d

return O.trim()

best answer from someone else

m = arguments[0]
i = 6
r = '' 
for (; i; i && (r += ' '))
  for (j = -i--; j < m.length-i; r += t > ' ' ? t : '.')
    t = m[j += 6] || '.'  
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.