1. RE: Decoder

Alex Blanchette wrote:
 
> Okay, I know I'm probably starting to get annoying but I learn better 
> through
> person to person help, I understand the program where you press a key 
> and it
> tells you the code for it and everything, but I want to make a program
> where the user inputs the code and it tells them what it means. Do not 
> give
> me the full answer on how to do this, but set me in the right mind set, 
> on the
> proper path, Thanks.
> 
> Thy name is but a short lived word,
> Thy life is a forever ending story...

If you are referring to ASCII codes then you can print the result of a 
'code' with:

puts(1,code)  -- where 'code' is an integer

or if you want to get fancy:

printf(1,"ASCII code %d is '%s'\n",{code,code})

-- Brian

new topic     » topic index » view message » categorize

2. RE: Decoder

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...

new topic     » goto parent     » topic index » view message » categorize

3. RE: Decoder

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?

include get.e

constant
   Base16 = "0123456789ABCDEF"

integer nextchar
sequence encoded, decoded
decoded=""

encoded = prompt_string( "Enter codes (e.g. 48656C6C6F20576F726C64): " )

if length( encoded )/2 != floor( length( encoded )/2 ) then
   puts(1,"Error: Must have even number of characters")
   abort(1)
end if
for i = 1 to length( encoded ) by 2 do
   if not(find( encoded[i], Base16 )) or not(find( encoded[i+1], Base16 
)) then
      puts(1,"Error: Invalid character(s) found")
      abort(1)
   end if   
   nextchar = ( find( encoded[i], Base16 ) - 1 )*16 + find( 
encoded[i+1], Base16 ) - 1
   decoded &= nextchar
end for

puts(1,decoded)

-- Brian

new topic     » goto parent     » topic index » view message » categorize

4. RE: Decoder

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
> 
> 

My version

include get.e

integer code
while 1 do
	code = prompt_number("Type in an ASCII code> ", {0,255})
printf(1,"ASCII code %d is '%s'\n\npress ESCAPE to exit or any key to
continue.\n\n",{code,code})
	if wait_key() = 27 then
		exit
	end if
end while


Below lies the signature of Lewis Townsend
Lewy T

new topic     » goto parent     » topic index » view message » categorize

5. RE: Decoder

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...

new topic     » goto parent     » topic index » view message » categorize

6. RE: Decoder

Alex Blanchette wrote:
> 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...
> 

Well, actually it is ASCII code... in hexadecimal format.
48656C6C6F20576F726C64 is "Hello World".  Decoding a string in decimal 
would require 3 numbers per letter instead of just two hexidecimal numbers.

I'll upload my version of ascii.ex to the archives.  It's easier to read
and lets you switch from decimal to hex.

-- Brian

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu