View previous topic :: View next topic |
Author |
Message |
decypherohm Just Arrived
Joined: 16 Nov 2002 Posts: 1 Location: World - Europe - Portugal - Lisbon
|
Posted: Tue Dec 10, 2002 12:16 am Post subject: Pascal help... |
|
|
I want to write a program the if u enter a word it will output the word but a letter in advance...(e.g. ABC = BCD; HAL = IBM etc...) but i could only do that with a single char... like this :
program blah;
Var
coded : char;
Begin
Writeln('Enter char:');
readln(coded);
coded:= Chr(coded)+ 1;
writeln('Coded text:', coded);
end.
not sure if this was like i made but its something like it! plz help
|
|
Back to top |
|
|
haydies Just Arrived
Joined: 19 Apr 2002 Posts: 0 Location: Hades
|
Posted: Tue Dec 10, 2002 12:29 am Post subject: |
|
|
Pascal strings are an array of char, just loop through the string.
For i := 1 to Length(TheString) Do Begin
AnotherString := AnotherString + Chr(Ord(TheString[i]) + 1 ) ;
End {For} ;
Some thing like that, I haven't used a pascal compiler other then delphi in some time so Chr and Ord might be called some thing else. But the strings are the same.
|
|
Back to top |
|
|
Wombat Trusted SF Member
Joined: 24 Apr 2002 Posts: 0 Location: Canberra
|
Posted: Tue Dec 10, 2002 1:49 am Post subject: |
|
|
What happens with Z? Does it get converted to A? You need to think about things like this!
|
|
Back to top |
|
|
haydies Just Arrived
Joined: 19 Apr 2002 Posts: 0 Location: Hades
|
Posted: Tue Dec 10, 2002 2:18 am Post subject: |
|
|
Nope, you have to deal with that.... easy enougth to check though.
Its jsut adding one to the asci code for the char. You can just check to see if the number is > Ord('Z') if it is, set it back to 'A' or what ever depending on what you want. But with out checking I'm fairly sure Z + 1 is printable.... can't remember off hand if Capitals are higher or lower ascii values then lower case.
My excuse is its gone midnight and I can't be arsed to run Delphi to check
|
|
Back to top |
|
|
Wombat Trusted SF Member
Joined: 24 Apr 2002 Posts: 0 Location: Canberra
|
Posted: Tue Dec 10, 2002 3:32 am Post subject: |
|
|
One higher than Z is [ and one higher than z is {, but if anyone sees these in your string they'll know immediately what is happening. Is this for simple encryption? If so, think about what you'd like your prog to do with spaces (one higher than space is !) and punctuation (one higher than , is - and one higher than . is / etc) and numbers (you'll get the next number obviously, and one higher than 9 is :).
|
|
Back to top |
|
|
haydies Just Arrived
Joined: 19 Apr 2002 Posts: 0 Location: Hades
|
Posted: Tue Dec 10, 2002 3:46 am Post subject: |
|
|
Not to mention that using that for encryption would last for about 5 seconds if some one wanted to crack it..... Its not really encryption at all at the end of the day.
My self, I like random number tables and some other funky code to make sure a char never gets encrypted to the same char twice. Makes it so much harder to decrypt... well, actualy, normaly thats for passwords so its more or less impossible to ever decrypt them
|
|
Back to top |
|
|
Wombat Trusted SF Member
Joined: 24 Apr 2002 Posts: 0 Location: Canberra
|
Posted: Tue Dec 10, 2002 5:00 am Post subject: |
|
|
Sure it would be easy to crack. So deciding if it's appropriate depends on what it's being used for. As it's so simple, maybe a better word than "encryption" would be "obfuscation".
The best word ever is "moist", but that means something completely different.
|
|
Back to top |
|
|
haydies Just Arrived
Joined: 19 Apr 2002 Posts: 0 Location: Hades
|
Posted: Tue Dec 10, 2002 5:06 am Post subject: |
|
|
Ye, I'd agree with that. Hardly worth it really....but I guess if you have to do it for some reason....
as its pascal and such a minor thing its probably a uni thing, sounds like the sort of app students get set. Pascal is a good teaching language as well. Even if its not OO for the most part (Dephi being only based on Pascal). I remember the days of the Amstrade CPC464 and my little pascal compiler..... oh my god, now I feel old.....
Any way, now I am going to bed before I get the bright idea of writeing some form of funky encryption thingy.... 3am, its time to sleep....
|
|
Back to top |
|
|
decypherohm Just Arrived
Joined: 16 Nov 2002 Posts: 1 Location: World - Europe - Portugal - Lisbon
|
Posted: Tue Dec 10, 2002 12:52 pm Post subject: |
|
|
When it gets Z+1 it will go to the next char in the ascii table...but this is just the beggining.... i complicate it alot... i have pascal language at schol but i am not very advanced...when that program ends.... it will encrypt the original word 10 times or more of a much more complicated encryption...
|
|
Back to top |
|
|
ShaolinTiger Forum Fanatic
Joined: 18 Apr 2002 Posts: 16777215 Location: Kuala Lumpur, Malaysia
|
Posted: Tue Dec 10, 2002 12:56 pm Post subject: |
|
|
decypherohm wrote: |
When it gets Z+1 it will go to the next char in the ascii table... |
Yup, which is not A
This is basically like ROT13 but it's not, it's ROT1
ROT13 is used commonly on Usenet just to stop lamers reading stuff and to post offensive/illegal things without breaking your TOS blatantly.
I encrypt all my messages here and on Usenet with ROT26, HARDCORE!
|
|
Back to top |
|
|
decypherohm Just Arrived
Joined: 16 Nov 2002 Posts: 1 Location: World - Europe - Portugal - Lisbon
|
Posted: Tue Dec 10, 2002 12:58 pm Post subject: |
|
|
nice... i didnt know that... but hey going to study the ROT13 encryption and make a program to encrypt/decrypt it!
Very nice... with witch program?!?!
|
|
Back to top |
|
|
b4rtm4n Trusted SF Member
Joined: 26 May 2002 Posts: 16777206 Location: Bi Mon Sci Fi Con
|
Posted: Wed Dec 11, 2002 1:01 am Post subject: |
|
|
mmm Re-inventing the Roman wheel.
2000 year old tech is still 2000 year old tech even if 5% of the worlds pop are smart enough to interpret it.
|
|
Back to top |
|
|
Wombat Trusted SF Member
Joined: 24 Apr 2002 Posts: 0 Location: Canberra
|
Posted: Wed Dec 11, 2002 1:30 am Post subject: |
|
|
There's nothing wrong with reinventing the wheel as a learning excercise. Have fun, decypherohm!
(when I tried it, it came out triangular)
|
|
Back to top |
|
|
haydies Just Arrived
Joined: 19 Apr 2002 Posts: 0 Location: Hades
|
Posted: Wed Dec 11, 2002 5:44 am Post subject: |
|
|
Hasn't every thing already been done? There is a thing called "Patterens" that are the building blocks of programmes. What makes a good programmer is expirance, i.e. how many things they know how to do. Once you get past a point there isn't a lot thats "new". Its just more complicated ways to use the same old little bits of code. Same as every thing else I guess, the more you know, the easier it gets. Every one has to start some where.....
|
|
Back to top |
|
|
decypherohm Just Arrived
Joined: 16 Nov 2002 Posts: 1 Location: World - Europe - Portugal - Lisbon
|
Posted: Wed Dec 11, 2002 9:22 am Post subject: |
|
|
Finished the programs... but it isnt the ROT13 encryption... i mean it rotates 13 times but when it get to Z it will no go to A it will go to the next char in ascii table!
|
|
Back to top |
|
|
ShaolinTiger Forum Fanatic
Joined: 18 Apr 2002 Posts: 16777215 Location: Kuala Lumpur, Malaysia
|
Posted: Wed Dec 11, 2002 11:22 am Post subject: |
|
|
decypherohm wrote: |
Finished the programs... but it isnt the ROT13 encryption... i mean it rotates 13 times but when it get to Z it will no go to A it will go to the next char in ascii table! |
Well fix it then
Aint ROT13 if it skips outside the roman alpha characters.
That's your next challenge
|
|
Back to top |
|
|
|