RE: Decoder
- Posted by Alex Blanchette <caithman at juno.com> Jul 31, 2004
- 517 views
Brian Broker wrote: > > Alex Blanchette wrote: > > > > No, I can get the code, I already know that, I want it so the user types > > in > > code, presses enter, and gets the "lamens"/decoded/english version of it > > > > Thy name is but a short lived word, > > Thy life is a forever ending story... > > OK, I know you weren't looking for a program but... something like this? > > <font color="#330033"></font> > <font color="#0000FF">include </font><font color="#330033">get.e</font> > <font color="#330033"></font> > <font color="#0000FF">constant</font> > <font color="#330033"> Base16 = </font><font > color="#00A033">"0123456789ABCDEF"</font> > <font color="#330033"></font> > <font color="#FF00FF">integer </font><font color="#330033">nextchar</font> > <font color="#FF00FF">sequence </font><font color="#330033">encoded, > decoded</font> > <font color="#330033">decoded=</font><font color="#00A033">""</font> > <font color="#330033"></font> > <font color="#330033">encoded = prompt_string( </font><font > color="#00A033">"Enter codes (e.g. 48656C6C6F20576F726C64): " </font><font > color="#330033">)</font> > <font color="#330033"></font> > <font color="#0000FF">if </font><font color="#FF00FF">length</font><font > color="#330033">( encoded )/2 != </font><font color="#FF00FF">floor</font><font > color="#330033">( </font><font color="#FF00FF">length</font><font > color="#993333">( </font><font color="#330033">encoded </font><font > color="#993333">)</font><font color="#330033">/2 ) </font><font > color="#0000FF">then</font> > <font color="#FF00FF"> puts</font><font color="#330033">(1,</font><font > color="#00A033">"Error: Must have even number of characters"</font><font > color="#330033">)</font> > <font color="#FF00FF"> abort</font><font color="#330033">(1)</font> > <font color="#0000FF">end if</font> > <font color="#0000FF">for </font><font color="#330033">i = 1 </font><font > color="#0000FF">to </font><font color="#FF00FF">length</font><font > color="#330033">( encoded ) </font><font color="#0000FF">by </font><font > color="#330033">2 </font><font color="#0000FF">do</font> > <font color="#0000FF"> if not</font><font color="#330033">(</font><font > color="#FF00FF">find</font><font color="#993333">( </font><font > color="#330033">encoded</font><font color="#0000FF">[</font><font > color="#330033">i</font><font color="#0000FF">]</font><font color="#330033">, > Base16 </font><font color="#993333">)</font><font color="#330033">) </font><font > color="#0000FF">or not</font><font color="#330033">(</font><font > color="#FF00FF">find</font><font color="#993333">( </font><font > color="#330033">encoded</font><font color="#0000FF">[</font><font > color="#330033">i+1</font><font color="#0000FF">]</font><font color="#330033">, > Base16 </font> > <font color="#330033">)) </font><font color="#0000FF">then</font> > <font color="#FF00FF"> puts</font><font color="#330033">(1,</font><font > color="#00A033">"Error: Invalid character(s) found"</font><font > color="#330033">)</font> > <font color="#FF00FF"> abort</font><font color="#330033">(1)</font> > <font color="#0000FF"> end if </font> > <font color="#330033"> nextchar = ( </font><font > color="#FF00FF">find</font><font color="#993333">( </font><font > color="#330033">encoded</font><font color="#0000FF">[</font><font > color="#330033">i</font><font color="#0000FF">]</font><font color="#330033">, > Base16 </font><font color="#993333">) </font><font color="#330033">- 1 )*16 + > </font><font color="#FF00FF">find</font><font color="#330033">( </font> > <font color="#330033">encoded[i+1], Base16 ) - 1</font> > <font color="#330033"> decoded &= nextchar</font> > <font color="#0000FF">end for</font> > <font color="#330033"></font> > <font color="#FF00FF">puts</font><font color="#330033">(1,decoded)</font> > <font color="#330033"></font> > -- Brian > > YES!!! Finally somebody understood my question properly! That helps a lot except the code is ASCII code so it doesn't include letters. Thank you! Finally, I wanted to smash my computer into the wall because I couldn't figure it out. Thy name is but a short lived word, Thy life is a forever ending story...