{"id":14510,"date":"2026-08-24T01:00:00","date_gmt":"2026-08-24T05:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14510"},"modified":"2026-08-23T18:09:12","modified_gmt":"2026-08-23T22:09:12","slug":"hide-text-with-this-1-line-command","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=14510","title":{"rendered":"Hide text with this 1-line command"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"14510\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p class=\"wp-block-paragraph\">In the 1990s, it was pretty common to hide certain text using a special \u201ccipher\u201d called <strong>rot13<\/strong>. However, this wasn\u2019t really encryption; instead, it was just a way to hide non-sensitive text so its meaning wouldn\u2019t be immediately obvious. A common use was to hide spoilers for TV shows and movies, or to give the answer to a (dumb) joke:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><em>A clumsy paleontologist walked into an auditorium carrying a dinosaur skull.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Jung unccrarq arkg vf wnj qebccvat.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">One way to un-hide these messages is to write a program that rotates the letters in a message by 13 positions in the alphabet. Because English has 26 letters, rotation by 13 positions will hide the message, and rotation by another 13 positions will reveal the message.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Such a program doesn\u2019t need to be very long; a <a href=\"https:\/\/www.both.org\/?p=14507\">sample implementation<\/a> is only about 26 lines long. However, you can actually do it via the command line, without writing a program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Translating characters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>tr<\/strong> program translates characters from one set to another. In the simplest case, you can use <strong>tr<\/strong> to translate the letter A to the letter B, like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo ABC | tr A B \nBBC<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>tr<\/strong> program also supports ranges of letters. Lets say you wanted to translate all <em>uppercase<\/em> letters to become <em>lowercase<\/em> letters. You would specify A\u2013Z as the <em>letters to translate from<\/em> and a\u2013z as the <em>letters to translate to<\/em>, such as this command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo Hello World | tr A-Z a-z\nhello world<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also specify multiple ranges to translate <em>from<\/em> and <em>to<\/em>, as long as both sets are the same \u201csize.\u201d For example, to translate only the letters A\u2013C to become the letters X\u2013Z, <em>and<\/em> the numbers 1\u20133 to the numbers 7\u20139, you can just list both ranges on the same command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo Blue300 | tr A-C1-3 X-Z7-9\nYlue900<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Hiding text<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using this method, we can apply <strong>tr<\/strong> to \u201crotate\u201d letters in a message by 13 positions. That is, the letters A\u2013N and a\u2013n become M\u2013Z and m\u2013z, and the letters M\u2013Z and m\u2013z become A\u2013N and a\u2013n. The <strong>tr<\/strong> command line starts to look a little weird, but it is a valid way to specify multiple ranges on the command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo Hello World | tr A-Ma-mN-Zn-z N-Zn-zA-Ma-m\nUryyb Jbeyq<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Applying the <strong>tr<\/strong> command a second time reveals the original message:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo Hello World | tr A-Ma-mN-Zn-z N-Zn-zA-Ma-m | tr A-Ma-mN-Zn-z N-Zn-zA-Ma-m\nHello World<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I find this is easiest to use if I put the <strong>tr<\/strong> command in a shell script, so I can use it whenever I need it. This is essentially a \u201cwrapper\u201d to the <strong>tr<\/strong> command; it only runs the command and doesn\u2019t do anything else:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\ntr A-Ma-mN-Zn-z N-Zn-zA-Ma-m<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Because the shell script only runs the <strong>tr<\/strong> command and doesn\u2019t rely only any specific Bash features, this can run under any shell. That\u2019s why I\u2019ve used <code>\/bin\/sh<\/code> (the original Bourne shell), although in practice this is almost guaranteed to be a link to the Bash shell anyway.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Unix tr program makes it easy to convert characters<\/p>\n","protected":false},"author":33,"featured_media":4464,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[100,69],"tags":[104,147],"class_list":["post-14510","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-fun","tag-command-line","tag-fun"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14510"}],"version-history":[{"count":2,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14510\/revisions"}],"predecessor-version":[{"id":14557,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14510\/revisions\/14557"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/4464"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}