Running on Java 19-ea+23-1706 (Preview)
Home of The JavaSpecialists' Newsletter

3.10 Rot13Scrambler

Juppies 2 by Dr Heinz M. Kabutz

The letters in our scrambled word have to be the same letters that are in the original word, otherwise our unit tests won't work. We could create a Rot13Scrambler, which says += 13 for all characters between 'a' and 'm' and -= 13 for all characters between 'n' and 'z'. Thus, "helloworld" would become "uryybjbeyq".

Unfortunately, when I wrote this code in the session, I made a mistake in the Rot13Scrambler. I should have added an else statement in between the two if statements, otherwise any characters from a-m will have 13 added to them, putting them in the range of n-z, but then we will again deduct 13 from them, giving us the original characters. Thus, "helloworld" becomes "hellbjbeld". I decided to leave this in so that you can see that even a seasoned Java professional and Java Champion like me makes mistakes. We didn't have a proper unit test to check this code, and thus we did not realize that it was broken.


When you load these comments, you'll be connected to Disqus. Privacy Statement.

Table of Contents

We hope you enjoyed this tutorial. If you did, you will also enjoy our courses. We suggest you start with Extreme Java - Advanced Java, followed by Extreme Java - Concurrency Performance for Java 8.

About the Author

Heinz Kabutz Java Conference Speaker

Java Champion, author of the Javaspecialists Newsletter, conference speaking regular... About Heinz

Superpack '22

Superpack '22 Our entire Java Specialists Training in one huge bundle more...

Free Java Book

Dynamic Proxies in Java Book
Java Training

We deliver relevant courses, by top Java developers to produce more resourceful and efficient programmers within their organisations.

Java Consulting

We can help make your Java application run faster and trouble-shoot concurrency and performance bugs...

Java Emergency?

If your system is down, we will review it for 15 minutes and give you our findings for just 1 € without any obligation.