45596033957b2b6d7ef8fe6545e0b7e7

Rotation encoding with variable steps. This could get interesting

1
2
3
def rot_encode(s, offset=2)
   s.split('').map{ |char| (char.ord + offset).chr }.join
end  

Refactorings

No refactoring yet !

Avatar

bob

January 18, 2010, January 18, 2010 20:04, permalink

1 rating. Login to rate!

This is not a "rotation" because high things don't wrap back around. e.g. with offset=13 is is not Rot-13. Instead, it just increases the character value by a certain amount. Some characters might be mapped into unprintable characters.

45596033957b2b6d7ef8fe6545e0b7e7

Sam Figueroa

January 19, 2010, January 19, 2010 06:49, permalink

No rating. Login to rate!

You know what bob. You're right. I didn't notice it at the time but now it is butt obvious to me. So where is your refactoring then :P

F9a9ba6663645458aa8630157ed5e71e

Ants

January 19, 2010, January 19, 2010 09:31, permalink

1 rating. Login to rate!
Avatar

tardface

January 21, 2010, January 21, 2010 19:56, permalink

No rating. Login to rate!

assuming 26 letter alphabet

1
2
3
def rot_encode(s, offset=2)
   s.split('').map{ |char| ((char.ord - '0'.ord + offset) % 26 + '0'.ord).chr }.join
end
Avatar

tardface

January 21, 2010, January 21, 2010 19:57, permalink

No rating. Login to rate!

That should be 'a'.ord, not '0'.ord. Unless you want numbers, as well, but then it's more complicated.

Your refactoring





Format Copy from initial code

or Cancel