i got a problem wtih my encryption...
would you be kind to help me with this...i'm new to this c++ programing...
i have this expansion encryption method..where you will add a char in between the original text..example >>>>. josh..this could be >>>> jxoxsxhx...like that...
my program goes like this
main()
{
char string[10],count;
int x,y;
cout<<"ENTER TEXT:";
cin>>string;
count=strlen(string);
for(x=0;x<count;x++)
cout<<string[x]<<string[2];
//if i'll enter "JOSH" the output would be "JSOSSSHS"
//if i'll enter "jupi" the output would be "jpupppip"
getche();
}
//what i need to do is to store the output in another array.
example. array[] will be equal to the cout in the program above which is
string[x] and string[2]...>>>>> array[x]="string[x]" and "string[2]"
how will i do that?.....
how will i do it?
please help everyone..
22 3335
you could try Something like -
// Obviously you have to make sure that the original string is less than 10 chars....
-
-
char string2[sizeof(string*2)];
-
int count2;
-
-
for(int x = 0; x<count; x++)
-
{
-
count2 = 2*x;
-
string2[count2]=string[x];
-
string2[coount2 + 1] = string[2];
-
}
-
-
Although I'm sure there are far more elegant ways to do this
This dosent look encryption as your original characters remains as it is with newly added characters.
Try using Blow-Fish for encrypting the string and the blow-fish is available on the net.
Raghu
you could try Something like -
// Obviously you have to make sure that the original string is less than 10 chars....
-
-
char string2[sizeof(string*2)];
-
int count2;
-
-
for(int x = 0; x<count; x++)
-
{
-
count2 = 2*x;
-
string2[count2]=string[x];
-
string2[coount2 + 1] = string[2];
-
}
-
-
Although I'm sure there are far more elegant ways to do this
what will i output in this code?
string2?
how will i do it?
please help?
if you don't mind..can you give the whole code?
im just a newbie to C++;;
thanks..
If you want to output something at the end of it, you can still use cout....
eg
This code shoudl fit nicely into your current code...
Where you declare string and count, also declare string and count2...
where your forloop is, try the forloop in the original response.
ehhyyy....thanks lot...it worked..
hehehe
...thanks man...
ahm,,if you don't mind,can you help me with this also?
if i'll enter "brosert" the output would be "boet" and the missing letters ("rsr")
would be stored in another array....
This time...
Set up 3 arrays (you could probably do it with 2, but that would be more complex....), loop through, if we are on an even iteration store to one array, otherwise store to the other.
I'll assume you have three equal sized arrays called string1, string2, string3...
string1 recieves input (as before) in a null terminated string -
-
//Create a pointer to the location in the string that we're up to -> this means we
-
// will still be able to access the beginning of any string we need.
-
char *strin1ptr = string1;
-
char *string2ptr = string2;
-
char *string3ptr = string3;
-
-
bool is2 = true;
-
//loop while we have more characters in string1
-
while(string1ptr)
-
{
-
// if we are on an even character
-
if(is2)
-
{
-
// set this location to contain the character in string1
-
*string2ptr = *string1ptr;
-
//bump string2ptr along
-
string2ptr++;
-
}
-
else
-
//likewise for string3
-
*string3ptr = string1ptr;
-
string3ptr++;
-
}
-
//bump string1ptr along too
-
string1ptr++;
-
}
-
-
cout << string1 <<endl;
-
count << string2 <<endl;
-
count << string3 <<endl;
-
-
can you do it without using a pointer?
we're not yet using pointers...
we are only allowed to use array..and loop..
can you do it?
please...
in that case, use a for loop....imnstead of the while loop
eg -
int count = sizeof(string1);
-
for(int x=0; x<count; x++)
-
{
-
/Check whether x is a multiple of 2
-
if(x%2 == 0)
-
{
-
string2[x/2] = string1[x];
-
}
-
else
-
{
-
string3[x/2] = string1[x];
-
}
-
\brosert............
//the program you give me only works in a 6-letter word and a 7-letter word...
//here it is
main()
{
char string[10],count,string2[20];
int count2;
cout<<"ENTER TEXT:";
cin>>string;
count=strlen(string);
for(int x=0;x<count;x++)
{
count2 = 2*x;
string2[count2]=string[x];
string2[count2 + 1] = string[2];
}
cout<<string2;
getche();
//what's wrong with it.....my problem is that i want to expand the text...it should
work on text with 1-10 characters.....
if "i" is entered it would output.. "ii"...
if "you is entered it would output "yuouuu"...like that..
if "abcd" is enterd it would output "acbcccdcec"...
please help me...
please...
Part of the problem is that it always takes the THIRD character....
If your string is shorter than 3 characters, it takes a (probably) NULL character, which terminates the string, and would give you a single character output....
where you get string try making the following modification : -
int charAt =2;
-
-
count=strlen(string);
-
//If we have a short input, take the last letter instead of the third
-
if(count <charAt) count=charAt;
-
-
then at the point where you actually assign the value, use
string[charAt]
instead of
string[2]
in that case, use a for loop....imnstead of the while loop
eg -
int count = sizeof(string1);
-
for(int x=0; x<count; x++)
-
{
-
/Check whether x is a multiple of 2
-
if(x%2 == 0)
-
{
-
string2[x/2] = string1[x];
-
}
-
else
-
{
-
string3[x/2] = string1[x];
-
}
-
i also have a question brosert....why is it that the index of string2 and string3
is "x/2"? why is it not x?
because only half of the characters go in each string....
so string2 and string3 will be half the size of string1.
In c (and I think most languages) if we divide a number in a place where we can only use an integer, it will autometically round the number down....
so 0/2 = 0 (obviously)
but 1/2 = 0 (because we can only use the integer part of the answer).
this means, that if we always take the current value/2, we will always be entering into the correct box of each string (might need to think about that for a second....)
it means if string1 has 7 characters,
the ones in position 0,2,4,6 will become 0,1,2,3 in string2
the ones in position 1,3,5 will become 0,1,2 in string3
If you need a better explanation, I can try again....
brosert.......
this one also...it only works with letters with 4 characters above..
int count = sizeof(string1);
for(int x=0; x<count; x++)
{
/Check whether x is a multiple of 2
if(x%2 == 0)
{
string2[x/2] = string1[x];
}
else
{
string3[x/2] = string1[x];
}
waht should i do?
i can't figure it out..
please help..
Not real sure....
try changing
count = sizeof(string1) to = strlen(string1) (as you had in your first program....
Meanwhile I'll have a deeper look/think
- main()
-
{
-
char string1[10],string2[10],string3[10];
-
int x,count;
-
cout<<"ENTER TEXT TO COMPACT:";
-
cin>>string1;
-
count=strlen(string1);
-
-
for(int x=0; x<count; x++)
-
-
//Check whether x is a multiple of 2
-
if(x%2 == 0)
-
{
-
string2[x/2] = string1[x];
-
}
-
else
-
{
-
string3[x/2] = string1[x];
-
}
-
cout<<string2<<endl;
-
-
-
getche();
-
}
i did that but still it onlyy works to text with 4 characters above....
i couldn't figure out what to do...
Do you get the wrong output for smaller strings, or none at all?
Do you get the wrong output for smaller strings, or none at all?
i got the wrong output for smaller strings..like if i enter "abc" the
output is "ac@".... or "ab" i would get "aG@"....
what should i do with this?
please help..
Do you get the wrong output for smaller strings, or none at all?
i think the problem in this is the size of the string...but i realy can't figure ir out...
got a problem wtih my encryption...
would you be kind to help me with this...i'm new to this c++ programing...
i have this expansion encryption method..where you will add a char in between the original text..example >>>>. josh..this could be >>>> jxoxsxhx...like that...
my program goes like this -
main()
-
{
-
char string[10],count;
-
int x,y;
-
-
cout<<"ENTER TEXT:";
-
cin>>string;
-
count=strlen(string);
-
-
for(x=0;x<count;x++)
-
-
cout<<string[x]<<string[2];
-
-
//if i'll enter "JOSH" the output would be "JSOSSSHS"
-
//if i'll enter "jupi" the output would be "jpupppip"
-
-
getche();
-
}
-
//what i need to do is to store the output in another array.
example. array[] will be equal to the cout in the program above which is
string[x] and string[2]...>>>>> array[x]="string[x]" and "string[2]"
how will i do that?.....
how will i do it?
please help everyone..
Banfa 9,065
Expert Mod 8TB
jupi13 I can see no reason why you restarted your encryption thread. Double posting is against the forum rules and you could clearly see that your original thread was active.
Anyway please try to avoid starting more than 1 thread on the same subject in future.
Banfa
Administrator
Banfa 9,065
Expert Mod 8TB
Part of the problem will all the code samples/examples in this thread is that none of them are correctly handling strings.
You are using C strings rather than the C++ string class (I assume you have not been taught that yet). In C a string is an array of printable characters with a 0 or NULL terminator. To get the length of a string you should use the function strlen. The operator sizeof returns the length of the array that contains the string not the length of a string.
Then when using char * pointers to write characters into an array of char once you have finished if you want to use the array as a string then you should make sure that you have written a 0 terminator in the correct place.
And finally in this piece of code -
int charAt =2;
-
-
count=strlen(string);
-
//If we have a short input, take the last letter instead of the third
-
if(count <charAt) count=charAt;
-
the assignment on line 5 is the wrong way round.
Brosert -
Please check your private messages
Thanks,
sicarie
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phil Palmieri |
last post by:
Im using md5 to encrypt and decrypt plain text, this works fine...
When i try to run the same function on a binary file, it does not
decrypt correctly. Is there a way to encrypt binary files...
|
by: TomB |
last post by:
Anyone know of an example/tutorial for encrypting a binary file?
I'm able to encrypt/decrypt simple text files, but anything more complicated
craps out.
Thanks
TomB
|
by: Bonj |
last post by:
I was in need of an encryption algorithm to the following requirements:
1) Must be capable of encrypting strings to a byte array, and decyrpting
back again to the same string
2) Must have the same...
|
by: larry mckay |
last post by:
Hi,
Does anyone have any simple text string encryption routines that are
easy to implement? I'm trying to prevent users and system
administrators from figuring out how I implement things....
|
by: pintu |
last post by:
Hello everybody..
I hav some confusion regarding asymmetric encryption.As asymmetric
encryption it there is one private key and one public key.So any data
is encrypted using private key and the...
|
by: eggie5 |
last post by:
I have a form where a user can change his password, but I'm confused
on how to prevent this from being transmitted in plain text.
Well, I know how not to transmit it in plain text - use any type...
|
by: manmit.walia |
last post by:
Hello Everyone,
Long time ago, I posted a small problem I had about converting a VB6
program to C#. Well with the help with everyone I got it converted.
But I overlooked something and don't...
|
by: Wilson |
last post by:
i am learning to program using c++ and was set a task of making a
simple encryption algorithim. I choose to start with one where simply
each letter is replaced with its equivilent in the alphabet...
|
by: klenwell |
last post by:
Another request for comments here.
I'd like to accomplish something like the scheme outlined at this page
here:
http://tinyurl.com/3dtcdr
In a nutshell, the form uses javascript to hash...
|
by: Netwatcher |
last post by:
well, i started messing around with dictionaries, yet, most of the pages i found about them always talk about getting only one word out of it and turning it vice versa, i've been playing with that...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |