Printable Version of Topic

Click here to view this topic in its original format

Dream.In.Code _ C and C++ _ HELP TO CONVER A PASCAL CODE TO C

Posted by: biskot188 21 Nov, 2008 - 03:50 PM

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.

Posted by: 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.

Posted by: biskot188 22 Nov, 2008 - 12:05 AM

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 ...

Posted by: biskot188 22 Nov, 2008 - 01:30 AM

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 ..;(((

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)