Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
encryption program
Author Message
zylum

Posted: Mon Mar 08, 2004 6:32 pm   Post subject: encryption program

here is a simple encryption program i made... what can i do to improve it?

 code: const letters := 52 var key : array 1 .. letters of string var c : string procedure createKey     for i : 1 .. letters         key (i) := ""     end for     var next : int     for i : 1 .. letters         loop             key (i) := chr (Rand.Int (33, 126))             next := 1             for j : 1 .. letters                 if key (i) = key (j) and j not= i then                     next := 0                 end if             end for             exit when next = 1         end loop     end for end createKey createKey fcn encrypt (message : string) : string     var encrypted : string := ""     for i : 1 .. length (message)         if ord (message (i)) <= 90 then             encrypted += key ((ord (message (i)) - 38))         else             encrypted += key ((ord (message (i)) - 96))         end if     end for     result encrypted end encrypt fcn getKey (key : array 1 .. letters of string) : string     var keyString : string := ""     for i : 1 .. letters         keyString += key (i)     end for     result keyString end getKey fcn decrypt (message : string, key : array 1 .. letters of string) : string     var decrypted : string := ""     for i : 1 .. length (message)         for j : 1 .. letters             if message (i) = key (j) then                 if j <= 26 then                     decrypted += chr (j + 96)                 else                     decrypted += chr (j + 38)                 end if             end if         end for     end for     result decrypted end decrypt createKey var option : int var message : string loop     put "1) encrypt"     put "2) decrypt"     put "3) show key"     put "4) exit"     put "what do you want to do?"     get option     cls     case option of         label 1 :             put "enter message"             get message             put encrypt (message), "\n"         label 2 :             put "enter message"             get message             put decrypt (message, key), "\n"         label 3 :             put getKey (key), "\n"     end case     exit when option = 4 end loop

-zylum

Mazer

Posted: Mon Mar 08, 2004 6:58 pm   Post subject: (No subject)

I don't know a whole lot about encryption techniques but I do no that the exit statement should be inside the case construct if you don't want it to crash. (ie, "label 4: exit" and take out the exit when line, or add "label :" and leave the rest)
It looks pretty good, by the way.
Delta

Posted: Wed Apr 21, 2004 10:05 am   Post subject: (No subject)

ok first of all....
 code: key (i) := chr (Rand.Int (33, 126))

this is not good.... when creating your new key... this randomizes all the characters in the key...meaning some can be the same...meaning your ecryption does not work properly... at least theres a chance that it won't
Andy

Posted: Fri Apr 23, 2004 10:29 am   Post subject: (No subject)

i made an simple encryption program in c++ too lazy to convert it to turing, so here's my encrypt and decrpt functions btw it only works for 10 letters max or something like that...

//encryption program
string encrypt(char word[])
{
//used for holding data
char tempword[15],final[15];
int val[15],j,tempval;
string encrypted;

//encrypt the data
for (int i=0;i<strlen(word);i++)
val[i]=i;

for (i=0;i<strlen(word);i++)
{
j=rand()%strlen(word);
tempval=val[i];
val[i]=val[j];
val[j]=tempval;
}

for (i=0;i<strlen(word);i++)
{
tempword[i]=word[val[i]];
final[i]=val[i]+48;
}

tempword[strlen(word)]='\0';

final[strlen(word)]='\0';
strcat(final,tempword);

for (i=0;i<strlen(final);i++)
final[i]+=((i%3)-1)*i;

encrypted=final;
return encrypted;
}

//decryption program
string decrypt(string word)
{
//used for holding data
char tempword[15],final[15];
int val[15];
string decrypted;
for (int i=0;i<word.length();i++)
final[i]=word[i];
final[word.length()]='\0';
for (i=0;i<strlen(final);i++)
final[i]-=((i%3)-1)*i;

for (i=0;i<strlen(final)/2;i++)
{
val[i]=final[i]-48;
tempword[i]=final[i+(strlen(final)/2)];
}

tempword[strlen(final)/2]='\0';
for (i=0;i<strlen(tempword);i++)
final[val[i]]=tempword[i];

final[strlen(tempword)]='\0';

decrypted=final;
return decrypted;
}

its simple but its pretty good
white_dragon

Posted: Fri Apr 23, 2004 5:34 pm   Post subject: (No subject)

WOW!!!! out of all da possibilities i got da same character! anywho. yeah just like Delta said, use someting else rather than tat. good job
WhatAmIDoing

Posted: Fri Apr 23, 2004 8:43 pm   Post subject: (No subject)

it's a good idea but it won't work. you can't change the encrypyion back if u want. a code is a set thing not random. but good try
Catalyst

Posted: Fri Apr 23, 2004 10:17 pm   Post subject: (No subject)

hes right u need way of saving or sending the key along (too many non-alpha numeric chars for the person to write down, the chr codes would be better) and inputting the key into the prog other wise u can only decrypt the message from the instance of the program that created it which makes it useless
jdworrow

Posted: Sun Apr 25, 2004 9:00 am   Post subject: (No subject)

Well, I'm still a little rough around the edges with things in Turing. But I liked the basics of the encryption program. Very good idea to move forward on.
[/img]

Delta

Posted: Tue Apr 27, 2004 12:29 pm   Post subject: (No subject)

Here is my encryption program... its got a set key that allows proper encryption and decryption.(proper meaning it works correctly) give it a try.

 code: var start : int := ord ('A') var newword : string := "" function CryptIt (words : string) : string     var word : string := ""     for cnt : 1 .. length (words)         word := word + chr (start xor ord (words (cnt)))     end for     newword := word     result newword end CryptIt put "Type in a sentence" get newword : * put "The sentence encrypted looks like this" put CryptIt (newword) put "The sentence decrypted looks like this" put CryptIt (newword)
WhatAmIDoing

Posted: Wed Apr 28, 2004 11:24 am   Post subject: (No subject)

here is my encryption program
var sentence : string
var number : int
loop
put ""
get sentence : *
exit when sentence = "exit"
for i : 1 .. length (sentence)
number := ord (sentence (i))
if number = 90 then
number := 64
elsif number = 122 then
number := 96
elsif number = 32 then
number := 31
end if
put chr ((number) + 1) ..
end for
end loop

if u want to decrypt just keep typing in the letters and eventualyy yuo'll get back to original message
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 10 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: