Skip to content

Instantly share code, notes, and snippets.

@arn-e
Created September 20, 2012 04:35
Show Gist options
  • Save arn-e/3753996 to your computer and use it in GitHub Desktop.
Save arn-e/3753996 to your computer and use it in GitHub Desktop.
encrypt single key
def encrypt_single_key(key,value)
offset,encrypted, off_i = key,[] , 1
value.split('').each_with_index do |val, i|
val.ord >= 97 && val.ord <= 122 ? dist = val.ord - (offset % 26) : dist = val.ord
dist < 97 && dist != val.ord ? (encrypted.push (122 - (97 - (dist+1))).chr) : (encrypted.push dist.chr)
end
return encrypted.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment