A few years ago I saw a code that converted everything to 1s and 0s and it was easy to encode and decode from that but I can't find it.
Bit-wise not (~) applied to a string does exactly that very efficiently: $s = 'The quick brown fox jumps over the lazy dog';;
print unpack 'C*', $s;;
84 104 101 32 113 117 105 99 107 32 98 114 111 119 110 32 102 111 120
+32 106 117 109 112 115 32 111 118 101 114 32 116 104 101 32 108 97 12
+2 121 32 100 111 103
$t = ~$s;;
print unpack 'C*', $t;;
171 151 154 223 142 138 150 156 148 223 157 141 144 136 145 223 153 14
+4 135 223 149 138 146 143 140 223 144 137 154 141 223 139 151 154 223
+ 147 158 133 134 223 155 144 152
$u = ~$t;;
print unpack 'C*', $u;;
84 104 101 32 113 117 105 99 107 32 98 114 111 119 110 32 102 111 120
+32 106 117 109 112 115 32 111 118 101 114 32 116 104 101 32 108 97 12
+2 121 32 100 111 103
print $u;;
The quick brown fox jumps over the lazy dog
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|