Vcoderz Community
We create websites that have it all, beauty & brains
Lebanon Web Design & Development - Coddict
 

Go Back   Vcoderz Community > Computer Zone > Computers & Information Technologies

Notices

Computers & Information Technologies « Everything related to computers and internet. »

Reply
 
Share Thread Tools Search this Thread
Old 02-22-2007   #1
Jean
Administrator
 
Jean's Avatar
 
Last Online: 04-16-2018
Join Date: Dec 2005
Posts: 5,085
Thanks: 250
Thanked 3,555 Times in 2,245 Posts
Groans: 3
Groaned at 12 Times in 7 Posts
Default C++ Help

hey all, i need your help in this :

i need to write a program that performs the affine cipher
to write a function that takes a text from a .txt file and transform the letters into digits a>0 w b>1 ...

plz i need it ASAP

thx in advance





Jean is offline   Reply With Quote
Old 02-22-2007   #2
Boris®
Registered Member
 
Boris®'s Avatar
 
Last Online: 04-08-2008
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default

mmm, are you taking course cryptography or something ?

its very easy, i think there is a function that transforms ascii to integer, it will be easier than to write if letter=='a' then digit=0, if letter== .....

Last edited by Kingroudy; 02-22-2007 at 07:00 PM.
Boris® is offline   Reply With Quote
Old 02-22-2007   #3
Kingroudy
Super Moderator
 
Kingroudy's Avatar
 
Last Online: 02-16-2022
Join Date: May 2006
Posts: 5,580
Thanks: 1,888
Thanked 2,653 Times in 1,593 Posts
Groans: 55
Groaned at 35 Times in 32 Posts
Default Re: C++ Help

Code:
int i=0;
char str[500];
int strd[500];
ifstream b_file ( "example.txt" );
b_file>>str[0];
while (str[i]!='.')
{
switch (str[i])
{
       case 'a':
       case 'A':
       strd[i]=0;
       break;
// and here u go on and on and on for b and B, c and C...
}
       cout<<strd[i]<<' ';
       i++;
       b_file>>str[i];
       
}
__________________
click on 'Groan' to switch to my left testicle.

Last edited by Kingroudy; 02-22-2007 at 06:58 PM.
Kingroudy is offline   Reply With Quote
Old 02-22-2007   #4
Jean
Administrator
 
Jean's Avatar
 
Last Online: 04-16-2018
Join Date: Dec 2005
Posts: 5,085
Thanks: 250
Thanked 3,555 Times in 2,245 Posts
Groans: 3
Groaned at 12 Times in 7 Posts
Default Re: C++ Help

Actually, my friend need help in this, like it is, and i appreciate any help from the members here
Jean is offline   Reply With Quote
Old 02-23-2007   #5
lebanese_a
Registered Member
 
lebanese_a's Avatar
 
Last Online: 04-15-2018
Join Date: Aug 2006
Posts: 1,549
Thanks: 31
Thanked 213 Times in 151 Posts
Groans: 0
Groaned at 1 Time in 1 Post
Default Re: C++ Help

Quote:
Originally Posted by Kingroudy
Code:
int i=0;
char str[500];
int strd[500];
ifstream b_file ( "example.txt" );
b_file>>str[0];
while (str[i]!='.')
{
switch (str[i])
{
       case 'a':
       case 'A':
       strd[i]=0;
       break;
// and here u go on and on and on for b and B, c and C...
}
       cout<<strd[i]<<' ';
       i++;
       b_file>>str[i];
       
}
Donno how to work with C++ so I am commenting 7assab ma fhemet the code based on my knowledge of VB.NET

1-" case 'a':
case 'A':"

in VB.NET you can uppercase or lower case the input (UCase, or LCase) that should remove 1 case through the code and make it smaller if it can be done in C++.
if it can't you should write a function (if they exist in C++) that does that, it will come in handy in big apps.

Kamena about the program, why don't you take the ascii chart, and lets say "A"'s ASCII # is 13 (it's not, I am just giving an example) you can make the app take the ascii # and do minus "ASC(A) - 1" ya3neh for A we will have:

Result = 13 (A's number) - 12 (A-1) that will give 1, for B it will be 14 - 12 = 2 w ... this way you could make one very small code and loop it arround the whole text!
lebanese_a is offline   Reply With Quote
Old 02-23-2007   #6
Kingroudy
Super Moderator
 
Kingroudy's Avatar
 
Last Online: 02-16-2022
Join Date: May 2006
Posts: 5,580
Thanks: 1,888
Thanked 2,653 Times in 1,593 Posts
Groans: 55
Groaned at 35 Times in 32 Posts
Default Re: C++ Help

the switch case statement is a C++ statement very similar to the if else, so there might be a confusion in the way u understood the code.
and then, i already told john, i did not learn how to do such stuff yet, but i promised him to do something working and i did. I'm sure that it should be done with the ASCII thingy, maybe i can make after some 1 hour of thinking and trying, but he was on a hurry, and i havent learnt those stuff yet.
__________________
click on 'Groan' to switch to my left testicle.
Kingroudy is offline   Reply With Quote
Old 02-24-2007   #7
Dazlingo
Registered Member
 
Dazlingo's Avatar
 
Last Online: 12-13-2007
Join Date: Jan 2007
Posts: 51
Thanks: 0
Thanked 3 Times in 2 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default Re: C++ Help

a switch case ???
lol
just do smth lice c-'a' , where char c="current char"
of course u could use tolower to set them all to lower characters
Dazlingo is offline   Reply With Quote
Old 02-24-2007   #8
Jean
Administrator
 
Jean's Avatar
 
Last Online: 04-16-2018
Join Date: Dec 2005
Posts: 5,085
Thanks: 250
Thanked 3,555 Times in 2,245 Posts
Groans: 3
Groaned at 12 Times in 7 Posts
Default Re: C++ Help

Quote:
Originally Posted by Dazlingo
a switch case ???
lol
just do smth lice c-'a' , where char c="current char"
of course u could use tolower to set them all to lower characters

dazlingo, can you please help in this ? i mean can you write it all ?
thx in advance
Jean is offline   Reply With Quote
Old 02-24-2007   #9
ZeRaW
Registered Member
 
ZeRaW's Avatar
 
Last Online: 04-15-2018
Join Date: Feb 2006
Posts: 624
Thanks: 2
Thanked 299 Times in 276 Posts
Groans: 0
Groaned at 1 Time in 1 Post
Default Re: C++ Help

Quote:
Originally Posted by Dazlingo
a switch case ???
lol
just do smth lice c-'a' , where char c="current char"
of course u could use tolower to set them all to lower characters
yep this is the correct thinking :P, here ya go:
Code:
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

void main(void)
{
	FILE * fp = fopen("text.txt","r");
	FILE * outFile = fopen("textout.txt","w");
	//the deal is character 'a' starts at index
	//97 in the ascii set and z is 122
	//so we just do character - 97
	//this wont support characters that are not in the range of 
	//a-z or A-Z
	char c = fgetc(fp);
	while(c != EOF)
	{
		c = tolower(c);
		c -= 97;
		fprintf(outFile,"%i",c);
		c = fgetc(fp);
	}
	fclose(fp);
	fclose(outFile);
}
__________________
I pwn n00bs
ZeRaW is offline   Reply With Quote
Old 02-24-2007   #10
Jean
Administrator
 
Jean's Avatar
 
Last Online: 04-16-2018
Join Date: Dec 2005
Posts: 5,085
Thanks: 250
Thanked 3,555 Times in 2,245 Posts
Groans: 3
Groaned at 12 Times in 7 Posts
Default Re: C++ Help

i need to know where's the mistake in here?
Code:
#include
using namespace std;
#include
#include 
using std::ofstream;


//funtion to convert letters into numbers
//function should have the array of numbers as output
void tonumbers(char str[])
{
    int i=0,strd[500];
    

 if(str[i]!=' ')
    {
 switch (str[i])
    {
       case 'a':
       strd[i]=0;
       break;
       cout<>str[0];

    cout<<"enter the multiplier ";
    cin>>mul;
    cout<<"enter the shift key ";
    cin>>key;
    cout<<"enter the plaintext ";
    cin>>plaintext;
    y=tonumbers(plaintext);
    encipher (y);
    


}
Jean is offline   Reply With Quote
Reply

  Vcoderz Community > Computer Zone > Computers & Information Technologies



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:52 AM.


Lebanon web design and development
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Share