Stupid sodding segmentation faults... I never had them at uni but get them all the time now
#include#include using namespace std; int main (int argc, char * const argv[]) { char* buffer; long size, x = 0; char packet[35]; char output[35]; const int cypher[35] = {2, 4, 6, 11, 15, 20, 23, 30, 34, 9, 12, 16, 19, 24, 27, 29, 32, 36, 5, 8, 10, 13, 18, 21, 25, 28}; ifstream input("crypt0.dat", ios::in|ios::binary|ios::ate); if(!input) { cout<<"Error: Could not open input file\n"; return 1; } size = input.tellg(); size = input.tellg(); input.seekg(0, ios::beg); buffer = new char[size]; input.read(buffer, size); input.close(); while(x <= size) { for(int i = 0 ; i <= 35 ; i += 1) { packet[i] = buffer[x]; x += 1; } for(int i = 0 ; i <= 35 ; i += 1) { output[i] = packet[cypher[i]-1]; cout<
[Error: Irreparable invalid markup ('<output[i];>') in entry. Owner must fix manually. Raw contents below.]
Stupid sodding segmentation faults... I never had them at uni but get them all the time now
<lj-cut>
<pre>
#include <iostream>
#include <fstream>
using namespace std;
int main (int argc, char * const argv[])
{
char* buffer;
long size, x = 0;
char packet[35];
char output[35];
const int cypher[35]
= {2, 4, 6, 11, 15, 20, 23, 30, 34, 9, 12, 16, 19, 24, 27, 29, 32, 36, 5, 8, 10, 13, 18, 21, 25, 28};
ifstream input("crypt0.dat", ios::in|ios::binary|ios::ate);
if(!input)
{
cout<<"Error: Could not open input file\n";
return 1;
}
size = input.tellg();
size = input.tellg();
input.seekg(0, ios::beg);
buffer = new char[size];
input.read(buffer, size);
input.close();
while(x <= size)
{
for(int i = 0 ; i <= 35 ; i += 1)
{
packet[i] = buffer[x];
x += 1;
}
for(int i = 0 ; i <= 35 ; i += 1)
{
output[i] = packet[cypher[i]-1];
cout<<output[i];
}
}
return 0;
}
</pre>
</lj-cut>
The idea is that it takes the first 36 characters, re orders them according to a cypher and spits out the answer to the screen, but then my code never works like i want it too
<lj-cut>
<pre>
#include <iostream>
#include <fstream>
using namespace std;
int main (int argc, char * const argv[])
{
char* buffer;
long size, x = 0;
char packet[35];
char output[35];
const int cypher[35]
= {2, 4, 6, 11, 15, 20, 23, 30, 34, 9, 12, 16, 19, 24, 27, 29, 32, 36, 5, 8, 10, 13, 18, 21, 25, 28};
ifstream input("crypt0.dat", ios::in|ios::binary|ios::ate);
if(!input)
{
cout<<"Error: Could not open input file\n";
return 1;
}
size = input.tellg();
size = input.tellg();
input.seekg(0, ios::beg);
buffer = new char[size];
input.read(buffer, size);
input.close();
while(x <= size)
{
for(int i = 0 ; i <= 35 ; i += 1)
{
packet[i] = buffer[x];
x += 1;
}
for(int i = 0 ; i <= 35 ; i += 1)
{
output[i] = packet[cypher[i]-1];
cout<<output[i];
}
}
return 0;
}
</pre>
</lj-cut>
The idea is that it takes the first 36 characters, re orders them according to a cypher and spits out the answer to the screen, but then my code never works like i want it too
