» tagged pages
» logout
Unix
Return to My SysAd Blog

Perform Elementary Encryption with tr Command

Tags Applied to this Entry

1 person has tagged this page:
Reading the "Stars and Stripes" newspaper today, I ran across the popularly syndicated JUMBLE puzzle, which is a scrambled word game. Interestingly enough, the versatile UNIX tr command came to mind again. By providing a jumbled alphabet key, the UNIX tr command can perform an elementary encryption operation. Here is a simple example.

To "encrypt" the contents of mysysad.txt in uppercase.
# sh
# cat mysysad.txt | tr '[a-z]' '[A-Z]' | tr '[A-Z]' "PETRUSCMANFXZJOIVKBGWHDYLQ" > mysys.txt

# more mysys.txt
GMU GKPJBXPGU WGAXAGL IKOHARUB HUKBPGAXGL DAGMAJ WJAY.

To "decrypt" the contents of mysys.txt in lowercase (original state)
# cat mysys.txt | tr "PETRUSCMANFXZJOIVKBGWHDYLQ" '[a-z]'

Or use the echo command per Denis' (commenter) suggestion
# echo "GMU GKPJBXPGU WGAXAGL IKOHARUB HUKBPGAXGL DAGMAJ WJAY." | tr 'PETRUSCMANFXZJOIVKBGWHDYLQ' '[a-z]'
Username:
Password:
(or Cancel)