C/C++ :: Writing A Program Which Includes Encoding And Decoding A Message?

Oct 31, 2014

I am writing a porgram which includes encoding and decoding a message.Now I am doing the encoding part.

The goal is to encode a message using similar approach as Caesar Cipher. But instead of alphabets, I am going to use the entire ASCII code of total 128 codes to be the base.

And it is not a simple shifting, it is a rotation. This means if you want to shift 4 units from char <DEL>, it will come back to the first code in ASCII Code which is at dec 0 char <NUL> and starts the shifting again. It won't jump if the limit of ASCII Code is reached.

Here we've got 7 different malls' names and I am going to encode them with a shift n. I think n is free to set, so here I just set it as 5. This is also called the key.

I have written something and I think it should work, but after all it doesn't. And I don't get what is wrong.

Here is my program:

#include <iostream>
using namespace std;
const int NUMBER_OF_MALLS = 7;
const int MALL_NAME_LENGTH = 13;
const int NAME_SIZE = MALL_NAME_LENGTH + 1;
void encode(int key, char plain[], int length, char encoded[]) {
for (int i = 0; i < MALL_NAME_LENGTH; i++)

[code].....

Note that I am not going to use other libraries, just <iostream>.

View 13 Replies


ADVERTISEMENT

C/C++ :: Encoding And Decoding Text From TXT Files

Dec 4, 2014

I'm new to C++ and involving encoding and decoding text from text files. When I enter a file in the program just stalls.

#include <iostream >
#include <iomanip>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
char getmenuselection (char m);

{Code] .....

View 3 Replies View Related

C++ :: Creating Variable On Runtime - Message Decoding

Apr 10, 2013

I receive messages over a bus. Suppose there is a function to read the messages storing them into a struct defined as follows:

typedef struct
{
ULONG timestamp;
BYTE ID;
BYTE data_length;
BYTE data[8];
} MSG_FRAME;

Depending on the message ID different messages represent different values for one project.For example msg with ID 10 can include in the 8 bytes something like:

width: 6 bits
height: 6 bits
actpos: 12 bits
maxpos: 12 bits
minpos: 12 bits
range: 16 bits
total: 64 bits = 8 bytes

Printing the message is no big deal. But here comes the tricky part. I want to print out the specific information hidden in the 8 bytes. I can define the structures for every msg ID and compile the program with this "special" header file, but I want to do it during runtime of the program, loading the information regarding the msgs, because i can have different projects where the information for different msg IDs can differ.

I've a non-C file, where basically all the information is written. Lets stay frame named

GetStatus{
bit 0 - 7 width
bit 8 - 15 height
.
.
}
etc.

How to read it on runtime and decode the messages? On runtime I'm not able to create variables and structures anymore!

View 13 Replies View Related

Visual C++ :: Transferring Unicode String From One Program To Another With UTF-8 Encoding?

Mar 20, 2015

I'm transferring a unicode string from one program to another with UTF-8 encoding.

Program that is sending:

Code:
// Convert path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
CString arg = L" /PATH="" + CString(utf8_converter.to_bytes(path).c_str()) + L""";

Program that is retrieving:

Code:
// Restore original path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
std::wstring path = utf8_converter.from_bytes( argument );

Everything has worked fine, until running on a Japanese edition of Windows.

The "byte path" then looks something like "C:¥Users¥d✝?✝a ,?¥AppData¥Local¥Temp¥file.txt".

"from_bytes()" will throw an std::range_error exception "bad conversion".

The program works fine when working with Japenese writing inside paths in the English edition.

What could be causing the "bad conversion"?

View 10 Replies View Related

C/C++ :: Using Multiple Files And Includes

Mar 23, 2014

I am struggling with the concept of having different ccp's and header files. I made a really bad example project for representation, but basically my question is are any of the #includes unnecessary that I have? Technically it functions, but if I am doing it wrong I want to prevent myself from starting bad habits in the future. My code just basically uses strings and sets a name and prints it. My code is really bad, but I wanted to just use includes in such a way for a quick example.

//MAIN.CCP
#include "functions.h"
using namespace std;
int main()

[Code]......

View 1 Replies View Related

C :: Program Terminates Without Message

Jan 15, 2014

I'm trying to parallelize bottom's up merge sort algorithm. Firstly, i must have working procedural code.

I rember I had my code working last week but I made some changes ( probably to arguments passed to sort function ), i run my program several times without rebuilding it so i though it's still working.

Now i came back to my code and my program terminates without any message which confuses me. I debbuged merge function and it seems to work well, at the end i have sorted array.

fprintf doesn't print any value to my stdout.

whole code : [C] mergesort - Pastebin.com

View 4 Replies View Related

C++ :: How To Be Able To Type A Message Into Another Program (such As Notepad)

Jul 1, 2013

I want to be able to type a message into another program (such as notepad) using C++. How would I do that? Is there a function to do this, or an event, or something?

View 4 Replies View Related

C++ :: Creating A Program That Encodes And Decodes A Message?

Sep 10, 2014

I am starting this project on how to encode and decode messages that are inputted, how to start this?

View 4 Replies View Related

C :: Switch Case Character Scanf (also Includes Arrays)

Nov 10, 2014

I'm trying to write a code that is read character user 'e' or ' ' space also numbers I mean a number 'e' or space 'e' a number 'e' or space so forth.But i get absurd numbers. The program shows me the added number. If '
' entered the taking numbers will stop(scanf will stop).

Example input:

e 1 8 7 2 3 6
or e 1 e 8 e 7 e 2 e 3 e 6

Code: #include <stdio.h>
#define MAX 10
void addq ( int *, int, int *, int * ) ;
void test();

[Code]....

View 2 Replies View Related

C/C++ :: Vigenere Cipher Not Decoding

Mar 11, 2015

I was assigned to make a vigenere cipher using the function void vegenere(char* to_encrypt, char* key, char* encrypted) I got it to work for the encryption but i have to be able to decrypt the phrase too. I was assigned to write in a flag which indicated encryption or decryption. I tried to implement this but now it wont decrypt and i dont know why, all it does is put the same copy of decryption (which is really encrypted) multiple times until it crashes.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void decrypt(char *to_encrypt, char *key);
enum flag{encryption = 1, decryption = -1};

[Code] ....

Ok i found my dumb error of putting decrypt on an infinite loop which i fixed by putting it into the if statement after the encryption output. However now it says that the encrypted and decrypted outputs are identical without decrypting the ciphertext

View 5 Replies View Related

C :: Gender Program That Interpret M And F Inputs And Prints Guy / Girl Message

Apr 10, 2014

How do I write a program that'll interpret "M" and "F" inputs and print a "you're a guy" or "you're a gurl" message?

Code:
#include <stdio.h>
#include <conio.h>
char gender;
char main(void) {
printf("type M or F

[Code] ....

View 5 Replies View Related

C++ :: Program To Display Error Message If Variable Entered Not An Integer

Nov 8, 2013

I need to have a program display an error message if the variable entered isn't an integer but then I want it to cin again. I have this but it doesn't work:

cout << "Enter an Integer: " ;
for (;;) {
cin >> var;
if (!cin) {

[Code] ....

I am not sure how to do what I want and this doesn't work, it just repeats That wasn't an int.. over and over again.

View 8 Replies View Related

C :: Strcpy - How To Update Old String In Stars Array With New That Includes Correct Letters

Apr 25, 2013

This for loop replaces the stars ******** in an array that contains a word to be guessed with the correct letter (c) that the user inputs if the word contains that letter.

Problem: After every guess the same hidden string of stars ******* is displayed instead of ex: ***W**** (assuming W was entered by the user)

How can I update the old ******** string in the Stars array with the new string that includes the correct letters chosen, so after every correct guess at a letter in the word a new string is displayed including the correct letters chosen?

I'm pretty sure I have to use strcpy but not sure how to implement it using a loop.

Code:
for(i = 0; i < strlen(unscrambledWord); i++) {
if(unscrambledWord [i] == c) {
Stars[i] = c;
} }

View 1 Replies View Related

C++ :: Decoding Unicode Characters To String

Jan 6, 2013

I'm having some problems in receiving fileNames from Server to Client(C++) in Mac OS X. I send a serialized object , which has a char pointer with the fileName or sometimes a string object, when i receive it in the client, it seems to be having %F6 or %E9 ,etc . This issue don't arise in Windows OS though, even thought it's the same code. Is there anyway decoding these '%' characters back to their original form in Mac OS & Linux ..?

Fex characters i got into problems with : ǡ ȅ ȉ

It would be difficult to change the code in server, so if there's a way decoding the characters back to its original form, it would be easier.I'm using Boost Library for Serialization and i'm just looking for ways to decode %F6 back to ȅ in C++, like if some library is available ..?

View 1 Replies View Related

C :: Write Message Passing Interface Program For Implementing Graph Coloring?

Mar 21, 2013

write mpi-c program for implementing graph coloring?(mpi-message passing interface used for parallel programming)

View 2 Replies View Related

Visual C++ :: Program To Auto Login Website - Waiting With Message Loop

Aug 25, 2013

I am writing a program to auto login in a web site. Before making next attempt I have to wait for some time like some 10 seconds(it is configurable). But during waiting UI should not freeze. I wrote code something like this. Here event m_hEvent[1]) will be set by another thread after 10 seconds.The problem is UI still freezes some times!

while(1)
{
//m_hEvent[1] will be set by another thread after 10 seconds
dwRet = MsgWaitForMultipleObjects(1, &m_hEvent[1], FALSE, dwMilliseconds, QS_ALLINPUT);
ResetEvent(m_hEvent[1]);

[Code] ....

View 4 Replies View Related

C/C++ :: Decoding RFID Data Hexadecimal Math

Feb 2, 2015

I currently am stuck at getting the needed outcome data from my RFID card. I got it decoded but now I need to do a few more things in order to get the final card number off the back of the card.

The cryptic value was E********B**0**E** (covered to protect card)
Decrypting it turned into 0000003048D1263B

Now I have 3 more steps to take in order to get to my wanted card number.

Quote
Step 1) Mask off the lower 20-bits (which should give me 0x1263B) I am unsure of how to go about doing that using C++.

View 2 Replies View Related

Visual C++ :: Decoding RFID Data Hexadecimal Math

Feb 2, 2015

I currently am stuck at getting the needed outcome data from my RFID card. I got it decoded but now I need to do a few more things in order to get the final card number off the back of the card.

The cryptic value was E********B**0**E** (covered to protect card)

Decrypting it turned into 0000003048D1263B

Now I have 3 more steps to take in order to get to my wanted card number.

Step 1) Mask off the lower 20-bits (which should give me 0x1263B) I am unsure of how to go about doing that using C++.

Step 2) Divide by 2 to strip off the lower parity bit (which should be 0x931d). And again, I'm unsure of how to go about doing this in C++.

Step 3) Convert hexadecimal value to decimal value (which would equal my wanted card number). This should be easily done using C++ at this point - though hard to confirm that since I am on step 1).

Code:
const char* original = "0x931d";
unsigned long n = std::strtoul(original, nullptr, 16);

All of this looks to me like RegEX does to most people - complicated and not understanding why it does what it does but gives the correct output.

View 2 Replies View Related

C :: Mcrypt Lib And String Encoding

Feb 11, 2015

I've got an application here which connects over the internet to a webserver and sends some json strings. This is all working already.

Now I want to encode one string via mcrypt (because it seemed the easiest library of all) AES and send it over to the other server where it should get decrypted again and checked for validity.

I'll be using this sample code as "starting base". i've found it on the internet:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
* MCrypt API available online:

[Code] ....

The code works as it is, it encodes my string into a ciphered text and displays the text via the display function to stdout.

From previous projects I know I usually used Base64 for transporting strings via json, but in this example the string is encoded into "%d" - so decimals.. It works too, and I dont care if I send a base64 encoded string or these decimals but how would I calculate back the %d encoded string ? So how would a "undisplay()" class look alike ?

Or maybe there is an easier way to transport the string and re-decode it ?

I'd expect something like:

base64string = base64encode(ciphertext);
...
send base64string to host2
...
at host2:
ciphertext = base64decode(base64string)
...
and then mcrypt_decode that ciphertext...

View 1 Replies View Related

C :: How To Write In DOS Encoding Using Class FILE

Dec 12, 2013

How to write in DOS encoding using class FILE ?

View 5 Replies View Related

C/C++ :: Zip And Unzip Files Using Huffman Encoding

Apr 14, 2015

I am writing a program to zip and unzip files using Huffman Encoding. I have successfully Built my Huffman Tree but I am unable to traverse through it to retrieve code the code for each character in sample files using the GetCode() method.

Here is my zip.cpp file:

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cctype>
#include "huffman.h"
using namespace std;
void CountLetters(int frequency[]);
int main(int argc, char *argv[]) {

[Code] ....

Specifically I am having trouble with the following segment in zip.cpp where I want to go through my built tree and print out each character and it's associated ascii value using the GetCode() method in huffman.cpp

cout << " Here are the codes: "<< endl;
for(char ch = char(0); ch <= char(255); ch++)
//for(int i= 1; i < 256; i++ )
{ //int x = (char) i;
if(mytree.inTree('*'))

[Code] ....

View 8 Replies View Related

C++ :: Encoding Byte Array Data?

Apr 23, 2012

I'm trying to parse some binary data in the form of an array of bytes and I've come across something that is confusing me related to the representation of data as chars versus ints. It's a bit of a long story, but the byte array contains a mixture of character data and integer data which I' having trouble unravelling. The problem seems to arise from the issue below:

Code:
const char * ch_arr = "abcd";
const unsigned int * ui_arr = (const unsigned int*)ch_arr;
cout << ui_arr[0] << endl;
unsigned int ui = 'a';
ui = ui << 8;
ui |= 'b';
ui = ui << 8;
ui |= 'c';
ui = ui << 8;
ui |= 'd';
cout << ui << endl;

I expected both the output lines to be the same, since they contain the same bytes (I believe), but I get:

Code:
1684234849
1633837924

View 4 Replies View Related

C# :: Filtering Invalid Byte Sequences For UTF8 Encoding For A Postgre?

Jun 25, 2014

Basically, I am inserting data from an ODBC connection into a PostgreSql database using the COPY query, but the COPY query stops and returns this error...

Quote
ERROR: invalid byte sequence for encoding "UTF8": 0x92
CONTEXT: COPY [TableName], line 1: "189572|1-00-1202|1-|00-|1202||AP||1...
STATEMENT: COPY [TableName] FROM STDIN (DELIMITER '|', NULL '')

View 4 Replies View Related

C++ :: Universal Order / Spacing Of Character Encoding For Integer Digits?

Feb 7, 2012

I have a char *pch that points to an integer digit 1 or 2 or ... 9. To get the character that's 1 less, instead of converting to int, minus 1, then converting back to char, I tried (*pch -1) and that seemed to work. I suppose that's because the particular character encoding on my system is such that the digits are encoded in the same order and spacing as the integers they represent. So the question is does this "convenience" feature hold true for all character encoding systems?

View 10 Replies View Related

C :: Program Reading / Writing Files

Dec 10, 2013

program that I am working on. I want to use fgets() in my program so I could handle multiple words from a text(to be able to handle spaces). I get a weird result when running the program.

Code: #include <stdio.h>
#include <stdlib.h>
//#include "kim.h"
#include <string.h>
[code]....

View 4 Replies View Related

C :: Writing Log File In Multithread Program

Oct 20, 2014

I'm currently finishing writing some small application. I want to be able to log important information about the program execution to a logfile, and I have several questions.

First of all - I'd prefer to make the part that logs information to a file separate from the code I've already written. So, what interface should I expose to the rest of the program? Is one function void log(const char*); enough?

Another thing that came to my mind; my program runs two threads, and I want to be able to write to the log file from both threads, so the question is: Should I make sure that the writing to the file is mutually exclusive?

And if so, whose responsibility is it to make the logging to the file thread-safe? The actual part that does the logging (void log(const char*) for that matter), or the parts of the program that calls log(const char*) ?

And lastly, and probably less importantly, where is it customary to save the logfile? (the user's home folder maybe?)

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved