Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,307 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 791 people online right now. Registration is fast and FREE... Join Now!




HELP TO CONVER A PASCAL CODE TO C

 
Reply to this topicStart new topic

HELP TO CONVER A PASCAL CODE TO C

biskot188
21 Nov, 2008 - 03:50 PM
Post #1

New D.I.C Head
*

Joined: 21 Nov, 2008
Posts: 3

HI PEOPLE i know pascal so i develop a code that i was asked in it but i have no idea about c
cause i never learn anything about it...i used java but never c language until now ...
i created this code its a project for encryption and decription using aski code if someone could convert it in c i would be greatfull ....

CODE

program shfrovalka;
uses crt;
  var text:string;
  m,k,c,men:integer;
procedure cez(var text:string; var k:integer);
  begin
  clrscr;
   writeln('vvedite isxodniy text ');
    write('$~/> ');
    read(text);
   write('vvedite klu4 shifrovani9 ');
    readln(k);
   for m:=1 to length(text) do
    begin
     c:=ord(text[m])+k;
     if c>256 then c:=c-256;
     text[m]:=chr(c);
    end;
end;
procedure desh (var text:string);
  begin
   writeln('vvedite kluch deshifrovki' );
   readln(k);
    for m:=1 to length(text) do
     begin
      c:=ord(text[m])-k;
       if c<256 then c:=c+256;
      text[m]:=chr(c);
     end;
  end;
begin
  repeat
    clrscr;
    writeln('1 - shifrovka ');
    writeln('2 - deshifrovka ');
    writeln('3 - sosto9nie texta ');
    readln(men);
     case men of
      1:cez(text,k);
      2:desh(text); U?
      3:begin
         writeln(text);
         readkey;
        end;
     end;
  until men = 0;
end.


This post has been edited by biskot188: 21 Nov, 2008 - 03:51 PM

User is offlineProfile CardPM
+Quote Post


PsychoCoder
RE: HELP TO CONVER A PASCAL CODE TO C
21 Nov, 2008 - 04:36 PM
Post #2

loves.Coding(this);
Group Icon

Joined: 26 Jul, 2007
Posts: 12,288



Thanked: 372 times
Dream Kudos: 10775
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Sorry but we're not going to just do your work and convert it for you, that's now how this site works

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is offlineProfile CardPM
+Quote Post

biskot188
RE: HELP TO CONVER A PASCAL CODE TO C
22 Nov, 2008 - 12:05 AM
Post #3

New D.I.C Head
*

Joined: 21 Nov, 2008
Posts: 3

QUOTE(PsychoCoder @ 21 Nov, 2008 - 04:36 PM) *

Sorry but we're not going to just do your work and convert it for you, that's now how this site works

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.

ok i ll try ...

This post has been edited by biskot188: 22 Nov, 2008 - 01:31 AM
User is offlineProfile CardPM
+Quote Post

biskot188
RE: HELP TO CONVER A PASCAL CODE TO C
22 Nov, 2008 - 01:30 AM
Post #4

New D.I.C Head
*

Joined: 21 Nov, 2008
Posts: 3

anyway you realy make me open that c damn stupid book and read it ok i ve change it but still i have a problem to solve..

CODE
#include <stdio.h>
#include <string.h>
#include <conio.h>

char text[256];
int m,k,c,men;

/*Encrypt*/
void cez(char *Text)
{
    printf("%s\n", "give me the text");
    gets(Text);
    printf("%s\n", "give me the key ");
    scanf("%d", &k);

    for(m = 0; m < strlen(text); ++m)
    {
        c = text[m] + k;
        if(c > 256) c -= 256;
        Text[m] = c;
    }    
}
/*Decrypt*/
void desh(char *Text)
{
    printf("%s\n", "give me the decoding key ");
    scanf("%d", &k);

    for(m = 0; m < strlen(text); ++m)
    {
        c = Text[m] - k;
        if(c < 256) c+=256;
        Text[m] = c;
    }
}
int main()
{
    cez(text);
    printf("%s\n", text);
    
    desh(text);
    printf("%s\n", text);

    _getch();
    return 0;
}


this is the code i manage to convert from pascal to c now how can i put a simple meny ,,,
cause when i put a menu with if it doesnt work ...well i m not sure that i do this menu right...

CODE

#include <stdio.h>
#include <string.h>
#include <conio.h>

char text[256];
int m,k,c,men,x;
print("1-encryption 2-decryption")
scan("%d"&x);
if x=1 do
/*Encrypt*/
void cez(char *Text)
{
    printf("%s\n", "give text");
    gets(Text);
    printf("%s\n", "give me the key ");
    scanf("%d", &k);

    for(m = 0; m < strlen(text); ++m)
    {
        c = text[m] + k;
        if(c > 256) c -= 256;
        Text[m] = c;
    }    
}
/*Decrypt*/
else
void desh(char *Text)
{
    printf("%s\n", "give me the decoding key ");
    scanf("%d", &k);

    for(m = 0; m < strlen(text); ++m)
    {
        c = Text[m] - k;
        if(c < 256) c+=256;
        Text[m] = c;
    }
}
int main()
{
    cez(text);
    printf("%s\n", text);
    
    desh(text);
    printf("%s\n", text);

    _getch();
    return 0;
}

and the second problem of this code is that if i try to encrypt the letter o for example with a key 20 it doesnt show normal result whitch was i so i have a problem with the aski coding probably or something with that cause somehow it doesnt fit the english alphabet ..;(((

This post has been edited by biskot188: 22 Nov, 2008 - 01:52 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 06:45PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month