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>.
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.
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('*'))
I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.
I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.
What is the best way to do this? Even an outline algorithm will work.
I want to make a program that opens a text file and checks the usernames listed in the text files to see if the names are registered on a site such as twitter. How easy would this be to make, what things would I need to know?
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.
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
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 ..?
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++.
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:
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!
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.
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:
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...
I have to develop a program that will analyse these time-sampled voltage and current measurements over 24 hours and find the total energy used, mean and peak power consumption and Energy used over each hour of the 24 hour period.
How do I go about doing this? I also need to include at least one numerical integration technique. The file data contains over 50 thousand lines in the format mentioned above.
I have come up with code for this, but am currently having issues finalizing it. It seems that it only puts out some of the numbers in a numerical order, but not all from both text files.
So I'm trying to output 2 different text files, one has customer names and the other has items they are selling. I gave each customer an ID and each of their items has the same ID. Only problem is when I try to output it, it only outputs the first item with the same ID. I do not want to display the ID number at all, I think getline would show it so I am not using it.
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:
I have been working on code for quite some time and am able to successfully read in a text document and take certain words and information that I need. The issue is that I need to read in close to 100 plus documents and was wondering how I could read in the multiple documents. I thought about creating a structure of arrays and have each text document be an element and walk through taking each document but I am not sure how this works.
I want to read the text file line by line, each time I find an instruction (that is, the keywords *sum or *subtract) I want to make a summation (in the case of *sum) of all the numbers in each of the following lines, and repeat until the next instruction appear. So the text file above should generate:
how can I implement a dictionary(I'm guessing a dictionary is the best way to go here) so that when I read the string *sum i can call a function that does the summation of the following lines.
the size of the text file may be big (several mb) and the number of different instructions to search for may be in the magnitude of hundreds.
i am trying to doing my project what is: Diff - The program should compare two text files and list the differences, i.e. lines and columns of the beginning and the end of a given difference.
I want to make a program that can know the current time and create a new .txt file.For example if its Monday to day then when its Tuesday it crates a new txt file called Tuesday.I really don't know how to go about this.I know i will need to use the time.h library.
I'm writing a code obfuscator in C. Debugger shows no errors in the code, but the program crashes after compiling -- I'm guessing it has something to do with while loops or reading data from files.
Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // list off all replaced elements typedef struct ReplaceList { char *from;// from string char *to;// to string (random)
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 '')