473,811 Members | 3,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hi need help in 2 projects ..:))

2 New Member
hello my friends .my first problem...i ve develop an algorith of the casear encryption but i have an error and i cant make it work..the decryption works fine but i have problem with the encryption and an error here is the error it seems right but dunoo "%s" -= "Z" - "A"; c2016..:( anyone could help..


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

void menu ( void ) {
printf("Please enter a number: \n"
"1-Encrypt\n"
"2-Decrypt\n"
"3-Exit\n"
"prompt > ");
fflush( stdout );
}

int getchoice ( void ) {
char buff[BUFSIZ];
int choice = 0;
do {
menu();
if ( fgets( buff, sizeof buff, stdin ) != NULL ) {
/* success reading a line, does it make sense? */
if ( sscanf( buff, "%d", &choice ) != 1 ) {
printf( "Enter a number\n" );
}
} else {
/* user EOF, just exit now */
choice = 3;
}
} while ( choice < 1 || choice > 3 );
return choice;
}

void encode ( void )
{
char buff[BUFSIZ];
int i = 0;
int shift_value;
printf( "Doing encrypt\n" );
printf("\nPleas e enter the text you wish to encrypt: ");
fgets(buff, sizeof(buff), stdin);
if ("%s" > "Z")
{
"%s" -= "Z" - "A";
}
printf("\nEnter your encryption shift value (anything from +-1 to 25): ");
scanf ("%i", &shift_value );



{
while ( buff[i] != '\0' )
{
buff[i] = buff[i] + shift_value;
i++;

}
}
printf("\n Your encrypted text is: %s \n", buff);
}
void decode ( void )
{
char buff[BUFSIZ];
int i = 0;
int shift_value;
printf( "Doing decrypt\n" );
printf("\nPleas e enter the text you wish to decrypt: ");
fgets(buff, sizeof(buff), stdin);
printf("\nEnter your encryption shift value (anything from +-1 to 25): ");
scanf ("%i", &shift_value );

{
while ( buff[i] != '\0' )
{
buff[i] = buff[i] - shift_value;
i++;
}
}
printf("\nYour decrypted text is: %s \n", buff);
}
int main ( ) {
int choice;
while ( (choice=getchoi ce()) != 3 ) {
if ( choice == 1 ) {

encode();
} else
if ( choice == 2 ) {
decode();
}
}


return 0;
}


well thats my first problem my second is that i have made 2 separate codes for the affine algorith encryption decryption but whenever i try to make them under a case or if so i can have a simple menu like 1) encryption 2)decryption it always dont work...:(((

here is the code for encryption
#include<stdio. h>
#include<string .h>
void main()
{
int ch,a1,b1,a,b,c, d,d1[15],h,n,i=0;
char str1[80],ek[80];
printf("Dwse to keimeno\n");
gets(str1);
do
{
printf("Dwse to kleidi\na:");
scanf("%d",&a);
printf("\nb:");
scanf("%d",&b);
a1=a;
b1=b;
b=26;
d=1;
while(d!=0)
{


c=a/b;

d=a%b;
d1[i]=d;
a=b;
b=d;
i=i++;



}

n=i-1;





if(d1[n-1]==1)
{
printf("\nOi ariumoi einai prvtoi metaji tous\n\n");
ch=1;

}
else
{
printf("\nOi ariumoi den einai prvtoi metaji tous\n\n");
ch=0;
}
}
while(ch==0);
a=a1;
b=b1;
printf("\nTo kleidi einai (%d,%d):\n",a,b );

printf("\nTo keimeno einai %s to mikos toy %d \n",str1,strlen (str1));
n=strlen(str1);

ek[n]='\0';
h=strlen(ek);
for (i=0; i<h; i++)
{
str1[i]=str1[i]-97;
ek[i]=((a*str1[i]+b)%26)+97;
printf("%c -> %d to \n",str1[i]+97,str1[i]);
}

printf("\n\nTo kriptografhmeno keimeno einai:%s \n",ek);
for (i=0; i<h; i++)
{
printf("%c -> %d \n",ek[i],ek[i]-97);
}
printf("To kriptografhmeno keimeno einai:%s \n\n",ek);

}


and here is for the decription ..any ideas how this can be made in one single code with the simple if or case menu..:)
#include<stdio. h>
#include<string .h>
void mul(int a1,int b1,int *d,int *x,int *y);
void main()
{
int ch,xx,a1,b1,a,b ,c,d,d1[15],h,n,x,key,y,i= 0;
char str1[80],dk[80];
printf("Dwse to keimeno\n");
gets(str1);
do
{
printf("Dwse to kleidi\na:");
scanf("%d",&a);
printf("\nb:");
scanf("%d",&b);

a1=a;
b1=b;
b=26;
mul(a,b,&d,&x,& y);
key=x;
if (key<0)
{
key=26+key;
}
printf("\n1/a:%d \n",key);

d=1;
while(d!=0)
{


c=a/b;

d=a%b;
d1[i]=d;
a=b;
b=d;
i=i++;



}

n=i-1;





if(d1[n-1]==1)
{
printf("\nOi ariumoi einai prvtoi metaji tous\n\n");
ch=1;

}
else
{
printf("\nOi ariumoi den einai prvtoi metaji tous\n\n");
ch=0;
}
}
while(ch==0);
a=a1;
b=b1;
printf("\nTo kleidi einai (%d,%d):\n",a,b );

printf("\nTo keimeno einai %s to mikos toy %d \n",str1,strlen (str1));
n=strlen(str1);

dk[n]='\0';
h=strlen(dk);
for (i=0; i<h; i++)
{
str1[i]=str1[i]-97;
xx=(str1[i]-b)%26;/*to kano se periptosi pou o b einai megalos*/
if (xx<0)
{
xx=26+xx;
}

dk[i]=((key*(xx))%26 )+97;
printf("%c -> %d\n",str1[i]+97,str1[i]);
}
printf("\n\nTo kriptografhmeno keimeno einai:%s \n",dk);
for (i=0; i<h; i++)
{
printf("%c -> %d\n",dk[i],dk[i]-97);
}
printf("To kriptografhmeno keimeno einai:%s \n\n",dk);

}

void mul(int a1,int b1,int *d1,int *x1,int *y1)
{int c,d,x,y;
if(b1==0)
{
*d1=a1;
*x1=1;
*y1=0;


}
else{
d=*d1;
x=*x1;
y=*y1;



c=a1%b1;

mul(b1,c,&d,&x, &y);


*d1=d;
*x1=y;
*y1=x-(a1/b1)*(y);

}

}


thank you for the time you gonna spend in helping me..:))
ps the text in the printf is in greek as i m from greece;)
:gOOd:
Nov 21 '08 #1
2 1593
donbock
2,426 Recognized Expert Top Contributor
The following code snippet is from the function named encode. I can't identify the line numbers because you didn't use CODE tags [hint].
Expand|Select|Wrap|Line Numbers
  1. fgets(buff, sizeof(buff), stdin);
  2. if ("%s" > "Z")
  3. {
  4. "%s" -= "Z" - "A";
  5. }
These two uses of "%s" are totally illegal and should have raised compiler errors.

Another hint, it is a lot easier for us to help if you paste the compiler errors into your post, being careful to translate the line numbers in the errors so they correspond to the line numbers in the code excerpt you provide for us.

Instead of "%s" perhaps you meant *buf; but I can't be sure because I'm not sure what you're doing.

Instead of "A" and "Z" you probably meant 'A' and 'Z'. The difference here is between string literals and character constants.
Nov 21 '08 #2
BISKOT188
2 New Member
The following code snippet is from the function named encode. I can't identify the line numbers because you didn't use CODE tags [hint].
Expand|Select|Wrap|Line Numbers
  1. fgets(buff, sizeof(buff), stdin);
  2. if ("%s" > "Z")
  3. {
  4. "%s" -= "Z" - "A";
  5. }
These two uses of "%s" are totally illegal and should have raised compiler errors.

Another hint, it is a lot easier for us to help if you paste the compiler errors into your post, being careful to translate the line numbers in the errors so they correspond to the line numbers in the code excerpt you provide for us.

Instead of "%s" perhaps you meant *buf; but I can't be sure because I'm not sure what you're doing.

Instead of "A" and "Z" you probably meant 'A' and 'Z'. The difference here is between string literals and character constants.
yes i meant that but i n that case it appear me 3 errors i m not at home at current time and i dont have a compiler i just have the codes with me so if it s not very hard can you compile to see the errors yourself..i m from a pda ..
Nov 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2658
by: Beach Potato | last post by:
Dear Y'all: I'm about to start porting a big old project written in anscient version of Delphi to something more stable, robust, supportable and maybe even portable. Since I haven't seriously touched C for large implementations, I'm seeking advice on what to use for development. My ultimate goal is to spend as less time on it as possible. I'll be writing it in Windows 32-bit environment, probably Win2000 or Win98. Planning to use a...
28
2490
by: Jed | last post by:
Hello to all! I have a couple of projects I intend starting on, and was wondering if someone here could make a suggestion for a good compiler and development environment. My goals are as follows: 1. Develop the project code on XP.
0
1367
by: rocsolid | last post by:
Current problem deals with three tables in my database. The "DOCUMENTSLIST" table has a one-to-many relationship to the junction table (DOCUMENTS/PROJECTS) which, in turn, has a many-to-one relationship to the "PROJECTS" table. The tables have the following fields: DOCUMENTSLIST DOCUMENTS/PROJECTS PROJECTS Document ID (P key) Documents/Projects ID (P key) Project ID (P key) Type Project ID (F key) Project Name DID Number Document...
10
2893
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work for multiple companies and work for multiple divisions within each company. Within each division he can work in multiple departments and within each department he can work with multiple groups. In each group he works on multiple projects. All the...
8
1849
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I need to build multiple mixed mode dll's used by a consumer application, do I have to implement multiple ManagedWrapper's (each embedded in indiviudal DLL project) and call all of them in my consumer application?
3
4418
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing version numbers on anything. The errors come and go with no apparent rhyme or reason. We do not...
15
4651
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
9
1619
by: Susan Bricker | last post by:
Greetings. My disclaimer first - I am a neophyte where VB and ACCESS are concerned, but I have been programming for quite a long time. That said ... I created a db at work using MS/ACCESS 2000 to assist in our software project management. The group I work with (online transaction processing for a major financial institution) works on various projects. Our programmers are assigned tasks for these projects. Projects are grouped into a...
46
2547
by: Bruce W. Darby | last post by:
This will be my very first VB.Net application and it's pretty simple. But I've got a snag in my syntax somewhere. Was hoping that someone could point me in the right direction. The history: My work involves creating custom packages of our software product for golf courses that purchase our software. The course data is kept as a back up in the event the course needs us to replace their custom files. Each course has a folder of it's own...
1
2073
by: JavaNme | last post by:
I need someone to debug the following errors for me, so that i can run the program. 1>------ Build started: Project: TheBankProject, Configuration: Debug Win32 ------ 1>Compiling... 1>BANK.cpp 1>c:\documents and settings\alan\my documents\visual studio 2005\projects\thebankproject\bank.cpp(161) : error C2043: illegal break 1>c:\documents and settings\alan\my documents\visual studio 2005\projects\thebankproject\bank.cpp(188) : error C2043:...
0
9730
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.