Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 ascii '32' doesn't put space - help.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
WynterJones




PostPosted: Sat Apr 08, 2006 1:43 pm   Post subject: ascii '32' doesn't put space - help.

Hello,

I had to make a really simple program for class. I have to turn a word to ascii and plus 2, a lot like the caeser cypher (pardon spelling, and perhaps I am incorrect about this tidbit). For the program I have done it, but I've decided I want to make it more complex throughout the year, and maybe when I am done playing with it I may know something, or made something cool involving encryption.

I was planning on making a chat program on turing and use whatever encryption program I make and use it for sening and recieving data to the two people in the chat. Instead of sending "hello, how are you" it would send a longer, key that if the teachers were to monitor wouldn't be able to read it. Why? Because my school is under strict rules with computers. We aren't even allowed to read blogs. It gets worse.

But anyways this is what I have :



code:

% -----------------------------------------------------------/
%  ___________________________.                             |*
% |;;| ! This is a virus ! |;;||          \`.  |\           |*
% |[]|---------------------|[]||     \`-. \ `.| \!,,        |*
% |;;|                     |;;||     \ \  `.\  _   (__      |*
% |;;|                     |;;||   `-.> \ ___   \    __     |*
% |;;|   The {3}ncryptor   |;;||  -/,o-./O  `.      ._`     |*
% |;;|                     |;;||   //   j_    |   `` _<`    |*
% |;;|    Programmed By:   |;;||  |\__(  \--'      '  \     |*
% |;;|                     |;;||  >   _    `--'      _/     |*
% |;;|     Wynter Jones    |;;||  |  / `----..   . /        |*
% |;;|_____________________|;;||   | (         `.  Y        |*
% |;;;;;;;;;;;;;;;;;;;;;;;;;;;||    \ \     ,-.-.| |_       |*
% |;;;;;;_______________ ;;;;;||     `.`.___\  \ \/=.`.     |*
% |;;;;;|  ___          |;;;;;||       `--,==\    )==\,\    |*
% |;;;;;| |;;;|         |;;;;;||        ,'\===`--'====\,\   |*
% |;;;;;| |;;;|         |;;;;;||      ,'.` ============\,\  |*
% |;;;;;| |;;;|         |;;;;;||     /`=.`Y=============\,\ |*
% |;;;;;| |___|         |;;;;;||    /`-. `|==============\  |*
% \_____|_______________|_____||  /`-._`=|=___=========     |*
%  ~~~~~^^^^^^^^^^^^^^^^^~~~~~~               - Wynter Jones|*
%  ----------------------------------------------------------\

setscreen ("graphics")

% Declaration of variables
var word, letter, enter : string
var l, random_int : int
var encrypt_word, spacer_key : string
var encrypt_file : int
var txt_message : int
var check_if_user_is_an_idiot : int := 0

% Encryption Proc
proc encrypt

    loop

        color (brightgreen)
        put "Your Message : " ..

        color (yellow)
        get word

        l := length (word)

        var ascii : array 1 .. l of int
        var change_letter : array 1 .. l of string
        var final_letter : array 1 .. l of string
        encrypt_word := ""
        spacer_key := "#"

        % Changing the letters to ASCII // encryption

        put skip

        for x : 1 .. l
            random_int := Rand.Int (14, 82)
            letter := word (x .. x)
            ascii (l) := ord (letter) + 2      % Encrypts

            % Not Working ! ?

            /* if ascii (l) = 32 then
             spacer_key := " "
             final_letter (l) := chr (ascii (l))
             encrypt_word += final_letter (l) + spacer_key + intstr (random_int)
             end if */

            final_letter (l) := chr (ascii (l))
            encrypt_word += final_letter (l) + spacer_key + intstr (random_int)
        end for

        color (white)
        put "Your Message is : ", skip
        color (brightred)
        put encrypt_word
        put skip

        open : encrypt_file, "message.txt", put

        put : encrypt_file, encrypt_word


        close : encrypt_file
    end loop

end encrypt

% Encryption Proc
proc decrypt

    loop

        color (brightgreen)
        put "Your Message : " ..

        color (yellow)
        get word

        l := length (word)

        var ascii : array 1 .. l of int
        var change_letter : array 1 .. l of string
        var final_letter : array 1 .. l of string
        encrypt_word := ""

        % Changing the letters to ASCII // encryption

        put skip

        for x : 1 .. l
            letter := word (x .. x)
            ascii (l) := ord (letter) - 2      % Decrypts
            final_letter (l) := chr (ascii (l))
            encrypt_word += final_letter (l)
        end for

        color (white)
        put "Your Message is : ", skip
        color (brightred)
        put encrypt_word
        put skip

    end loop

end decrypt

% The coolness factor*
Draw.FillBox (0, 0, maxx, maxy, black)
colorback (black)

% Title
color (white)

put "The {3}ncryptor"
put "// Encrypts a single word to a txt file"
put skip
color (white)
put "Options:"
color (yellow)
put "// type 'e' to encrypt word to txt file"
put "// type 'd' to decrypt word from txt file"
put skip
color (brightgreen)
put "Choice : " ..
color (brightred)
get enter

loop
    if enter = "e" then
        put skip
        color (brightpurple)
        put "-------------------------"
        color (brightblue)
        put "*************************"
        put skip
        color (grey)
        put "Encryptor : ", skip
        encrypt
    elsif enter = "d" then
        put skip
        color (grey)
        put "Decryptor : ", skip
        decrypt
    else
        check_if_user_is_an_idiot += 1
        if check_if_user_is_an_idiot = 3 then
            color (yellow)
            cls
            put "Please step away from the computer,"
            put "And discontinue further use of this machine."
            color (gray)
            put skip
            put "--- > This is an order, from the illuminati < ---"
            put skip
            color (white)
            put "We are disappointed with your lack of sense."
            put "Next time you feel the need to use this program,"
            put "Please make sure you use it."
            exit
        end if
        color (white)
        put skip
        put "Retry -- : // type 'e' to encrypt, or 'd' to decrypt"
        put skip
        color (brightgreen)
        put "Choice : " ..
        color (brightred)
        get enter
    end if
end loop


% -------------------------------------------------------
%      \    /\
%       )  ( ')
%      (  /  )          That is all.
%       \(__)|
%


What the encryption process is easy, and easily read by the code so I won't go into detail.

Note where I have "Working" in the encrypt proc. I have seen some ascii charts and it says 32 is a space. But when you input a space it enters it twice, and encrypts it onto another line. I want it all to be on one line. So I thought I should put that if statement in there, but it doesn't work. (I know it's commented) but even when it's not commented.

Anyone have any suggestions on encryption, or to my problem. Please don't refer me to a tutorial here, because I have read them, and not ready for the complicated encryptions. Baby steps.

Thanks.
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat Apr 08, 2006 2:58 pm   Post subject: (No subject)

A likely problem is this line in encrypt:

code:

get word


Change that to:

code:

get word : *

Which allows for more than one token to be entered. As for your decyption, it appears to be a little buggy - in decrypts fine, but does not parse the resultant output. So, one ends up with an odd string like "h!/5e!05l!3/l!16o!46" for "hello".

You may not need to worry about this for now, but the fact that there's so much repitition in your buffer characters is a sure sign of their existence. Anyone looking at your output will be struck by its length, and be curious as to why random kids are typing out such long essays while on a chat-line. Hence, they will be led to look at the output closely and will notice the repitition and hence hypothesize the existence of bulk in there. They will then proceed to do some simple ASCII manipulations and will quite quickly break the encryption. Not at all serious at your stage, but something to consider as you improve upon your algorithms.
WynterJones




PostPosted: Sat Apr 08, 2006 4:50 pm   Post subject: (No subject)

Thank you very much.

I have seen people use : * but was never told what it was for, so thank you for fixing that problem.

As for the decryption of the above program isn't set up for the encryption, yet.

The code so far is very faulty, and like you said won't be easily dismissed. Pretty much because :

hey there

=

j#68g#20{#49"#81v#62j#64g#73t#15g#69

lol not so great, but I am just learning and trying things.

Does anyone have any improvements? Or steps into the right direction to some not so complicated, but fun encryption processes?
WynterJones




PostPosted: Sat Apr 08, 2006 5:18 pm   Post subject: (No subject)

For anyone who cares :

I have made it add a space, and make the one part of the code I had before work, with help.

code:

       for x : 1 .. l
            letter := word (x .. x)
            ascii (l) := ord (letter) + 2      % Encrypts
            if ascii (l) = 34 then
                final_letter (l) := " "
                encrypt_word += final_letter (l)
            else
                final_letter (l) := chr (ascii (l))
                encrypt_word += final_letter (l)
            end if

        end for
Tony




PostPosted: Sat Apr 08, 2006 5:41 pm   Post subject: (No subject)

heh
code:

for x : 1 .. l

1 to L
_really_ difficult to tell the difference in that font

So you basically solved the problem of encripted spaces looking weird by not encrypting them. Ehh.. ok, but now it's easy to identify separate encrypted words.

Furthermore by noticing that you're not using characters a,b and have only 2 "weird characters": z+1, z+2 it becomes incredibly easy to crack the message.. even without tools.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
WynterJones




PostPosted: Sat Apr 08, 2006 9:02 pm   Post subject: (No subject)

Wow, your right.

I've created the code that ultimately defeats me. Thanks for the heads up, I'm not even sure why I even wanted the space to begin with.
md




PostPosted: Sun Apr 09, 2006 9:39 am   Post subject: (No subject)

It's not really even a cesar cypher since you are only shifting letters. Perhaps I shall write a good tutorial on encryption... one that starts off easy enough for anyone.
Delos




PostPosted: Sun Apr 09, 2006 12:32 pm   Post subject: (No subject)

Or you could delve into a bit of colloaboration and improve upon Mystic's and perhaps even convice Imm0rtal that his, uh, source code could be put to better uses in the right context... Wink
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Sun Apr 09, 2006 2:36 pm   Post subject: (No subject)

We shall see... but having until the end of the month with nothing to do for the most part means lots of free time to look into it.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: