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

Username:   Password: 
 RegisterRegister   
 Code / Decode
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Win OOPs




PostPosted: Tue Oct 01, 2002 8:34 am   Post subject: Code / Decode

Ok Tony.... [Soprano]

U suggested to come here......
i did Smile

a coding/decoding program
like the one they made to use in WWII... Rolling Eyes

But i need help making my own... using letters and numbers ....
So when the user inputs the message..... it should give the code in output.... and vice versa...

Thanx for the help.....
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Oct 01, 2002 9:22 am   Post subject: (No subject)

thx for comming. Here's the simpiest way to do so:

code:
var name:string :="abc"

for i:1..length(name)
put chr(ord(name(i))+1)..
end for


this will output "bcd" which is the next letter from the original. Such as A is B and B is C. to reverse it, you just have to change +1 to -1

now I guess this is quite easy to crack. So if you want to make it more compilcated you can change the +1 to some more complex math function.

The idea behind this is:
chr will output an ASCII character based on the interger provided
ord takes an ASCII value of character provided
+1 increases ASCII value obtained by 1 to code the message

I hope this helps.

Also a cool encoding method is to use a seeded random function, but I don't think WinOOT allows that. I know you can do that in VB though.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Win OOPs




PostPosted: Tue Oct 01, 2002 2:23 pm   Post subject: Alrighty....

Ok thanx... but Wut if i want to the user to input the message to encode....
and the alphabets will have a Same value.... each time so that if "A" is typed.... it can recognize it by same number enter.....

P.S. You can tell that i don't know anything about TURING.... but what happened was... I took the course... but then didn't even look at it for more than an year and a half.... and now I am taking it again.... Wink

And yes.... if you are suspicious.... this is not a project... or class work.....
I was going over some loops and strings and suddenly i thought of the idea... but then i got stuck and couldn't even think of anything.... except this.... :

code:

var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, co, code : int
var mess : string

a := 26
b := 25
c := 24
d := 23
e := 22
f := 21
g := 20
h := 19
i := 18
j := 17
k := 16
l := 15
m := 14
n := 13
o := 12
p := 11
q := 10
r := 9
s := 8
t := 7
u := 6
v := 5
w := 4
x := 3
y := 2
z := 1

for decreasing count:  26..1
for decreasing character: 122..97

put "Type 1 to enter a code.", " OR Enter 2 to type a message to Decode "
get co
delay (500)
cls

if co = 1
        then
    put "Please type in the code numbers to reveal the secret message (max number 26): "
    get code
elsif co = 2
        then
    put "Please type your message to Decode in the number code: "
    get mess

    delay (1000)
    cls



and the letters as variables... will equal to a Constant value and if user enters that "A" it would give the user 26.... no matter how many times... the letter comes in the message Shocked

I know this is the longer way of doing this program..... but had no choice....
And plz.... don't laugh at me ...... I might have sounded dumb... but i can't help it.... Mr. Soprano... Wink
Tony




PostPosted: Tue Oct 01, 2002 11:19 pm   Post subject: (No subject)

Hey, my program runs a loop from 1 to the length of the string, so it can code/decode a message up to 255 characters, including spaces. Just don't forget to put :* at the end of get as in get name:* to get all characters including spaces.

and try changing the value of the varaible in the program from "abc" to something else to see how it affest the output.

Also, don't worry about the way you do your programs. We all were new to all of this as some point. Thats why S.W.A.T. is here to help you Wink

And now that you know how to work with ASCII values, code/decode program should be easy.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Win OOPs




PostPosted: Wed Oct 02, 2002 4:47 am   Post subject: Thanx

Thanx that helped alot....

but i when i wrote the put command and when i put get name :*

it just gives me one output Shocked

Thanx for the support.... Neutral
Tony




PostPosted: Wed Oct 02, 2002 5:13 am   Post subject: (No subject)

ummm... well ya.

What get name:* does is that it takes everything you type as an input including spaces.

The problem with regular get is that if you have a SPACE as a part of your string, it will cut the string into two varaibles and part after the SPACE will be passed to the next get.

Such as if in code:
code:
get a
get b
put a
put b

for get a you type "blah blah", it will skip get b and for output a is "blah" and b is "blah"

if insdead of get a you would put get a:* it will take "blah blah" and put all of it into variable a.

I hope this explains how get statments work.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: