|
|
|||||||
| Computers & Information Technologies « Everything related to computers and internet. » |
![]() |
|
|
Share | Thread Tools | Search this Thread |
|
|
#1 |
|
Administrator
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
|
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 |
|
|
|
|
|
#2 |
|
Registered Member
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
|
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== .....
__________________
http://img215.imageshack.us/img215/6...ureswz40jo.pngya Last edited by Kingroudy; 02-22-2007 at 07:00 PM. |
|
|
|
|
|
#3 |
|
Super Moderator
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
|
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. |
|
|
|
|
|
#4 |
|
Administrator
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
|
Actually, my friend need help in this, like it is, and i appreciate any help from the members here
|
|
|
|
|
|
#5 | |
|
Registered Member
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
|
Quote:
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! |
|
|
|
|
|
|
#6 |
|
Super Moderator
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
|
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. |
|
|
|
|
|
#7 |
|
Registered Member
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
|
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 |
|
|
|
|
|
#8 | |
|
Administrator
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
|
Quote:
dazlingo, can you please help in this ? i mean can you write it all ? thx in advance |
|
|
|
|
|
|
#9 | |
|
Registered Member
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
|
Quote:
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 |
|
|
|
|
|
|
#10 |
|
Administrator
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
|
i need to know where's the mistake in here?
Code:
#include |
|
|
|
![]() |
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|