--- a/Character.st Mon Aug 17 17:36:37 2009 +0200
+++ b/Character.st Tue Aug 18 00:07:57 2009 +0200
@@ -1426,11 +1426,7 @@
A major advantage of rot13 over rot(N) for other N is that it
is self-inverse, so the same code can be used for encoding and decoding."
- (((self >= $a) and:[self < $n]) or:[(self >= $A) and:[self < $N]])
- ifTrue: [ ^ self + 13 ].
- (((self > $m) and:[self <= $z]) or:[(self > $M) and:[self <= $Z]])
- ifTrue: [ ^ self - 13 ].
- ^ self
+ ^ self rot:13
"
$h rot13
@@ -1438,6 +1434,31 @@
'The butler did it!!' rot13 -> 'Gur ohgyre qvq vg!!'
'The butler did it!!' rot13 rot13 -> 'The butler did it!!'
"
+!
+
+rot:n
+ "Usenet: from `rotate alphabet N places']
+ The simple Caesar-cypher encryption that replaces each English
+ letter with the one N places forward or back along the alphabet,
+ so that 'The butler did it!!' becomes 'Gur ohgyre qvq vg!!' by rot:13
+ Most Usenet news reading and posting programs include a rot13 feature.
+ It is used to enclose the text in a sealed wrapper that the reader must choose
+ to open -- e.g., for posting things that might offend some readers, or spoilers.
+ A major advantage of rot13 over rot(N) for other N is that it
+ is self-inverse, so the same code can be used for encoding and decoding."
+
+ (self isLetter) ifTrue:[
+ self isLowercase ifTrue:[
+ ^ 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' at:(self-$a+1+n)
+ ].
+ ^ 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ' at:(self-$A+1+n)
+ ].
+ ^ self
+
+ "
+ 'The butler did it!!' rot:13 -> 'Gur ohgyre qvq vg!!'
+ ('The butler did it!!' rot:13) rot:13 -> 'The butler did it!!'
+ "
! !
@@ -2746,5 +2767,5 @@
!Character class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Character.st,v 1.136 2009-03-23 14:44:16 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Character.st,v 1.137 2009-08-17 22:07:57 cg Exp $'
! !