Pascal (post: 1268088) wrote://Cool. A programming thread!
more to come because graduate level numerical analysis has decided that I will code every numerical technique under the sun (collapses from homework).
/*Bad Asc, a small, weak encrpytion program written by "Icarus".
* The purpose is to take a stream of text and convert it to the numeric
* equivalent mod some integer. */
//standard include statements for writing to the screen and files.
#include <iostream>
#include <fstream>
//just for convenience
using namespace std];
char ofilename[30];
//most likely I could have gotten away with just one variable,
//but for ease of reading I used two. 'a' holds the choice of
//operation.
char text, a;
ofstream ofile;
ifstream ifile;
cout<<"Would you like to (e)ncode or (d)ecode a file?" ;
cin>>a;
cout<<"Please enter the file name: ";
cin>>ifilename;
cout<<"Output goes to which file? ";
cin>>ofilename;
//open the files for reading and writing.
ifile.open(ifilename);
ofile.open(ofilename);
if(a=='e'){
cout<<"Please enter an integer between 70 and 100: ";
cin>>key;
//I might add a multiplication key here so that it multiplies
//by a random number first, then mods by 'key'
int count=0;
//I use ifile.get() here instead of just ifile>> to ensure that
//I preserve whitespace. I tried it without but decoding resulted in
//one long line of solid characters.
ifile.get(text);
ofile<<key<<endl;
//As long as we aren't at the end of the file:
while(!ifile.eof()){
//convert the character to it's ascii equivalent
x=static_cast<int>(text);
//divide by the key, and keep the remainder
quot= x / key;
rem= x % key;
//and write them to a file.
ofile<<quot<<" "<<rem<<" ";
count+=5;
//add five spaces to count.
//once it hits 80, print a new line.
if(count>75){
ofile<<endl;
count=0;
}
ifile.get(text);
}
}
//since they don't want to encrypt something, let's decrypt.
else{
//read in the key...
ifile>>key;
while(!ifile.eof()){
//and then the values. multiply and add accordingly
ifile>>temp;
x=temp *key;
ifile>>temp;
x+= temp;
//then the ascii value to character and write it
//to the file.
text= static_cast<char>(x);
ofile<<text;
}
}
//close the files and exit.
ofile.close();
ifile.close();
return 0;
}
Pascal (post: 1268190) wrote:Ahh... that's a fun type of program to build, I built my own using C#.NET for the next nations and states game. Its rather complex, but I don't intend on publishing it to the net at the current time . (Its always best to keep your encryption programs private instead of public)
Pascal (post: 1268088) wrote://Cool. A programming thread!
Most of my code can be found on my webpage:
http://www.tensor-industries.com
under the physics section... more to come because graduate level numerical analysis has decided that I will code every numerical technique under the sun (collapses from homework).
Slater (post: 1268427) wrote:I know C++, Java, HTML, Javascript, PHP, unix scripting, and MIPS ASM very well.
I also know a tiny, tiny bit of x86 ASM.
Icarus (post: 1268156) wrote:Yep yep.
I know some C++, and might be able to make sense of others.
Last thing I wrote was a small encryption program.
//most likely I could have gotten away with just one variable,
//but for ease of reading I used two. 'a' holds the choice of
//operation.
termyt (post: 1268770) wrote:I'm old school. I know C and Visual Basic best (as well as Lisp, Pascal, and some Assembler) and I'm a little weak on object-oriented programming. I’m working on picking up Java in my spare time, which I have little of
The upside is I’m doing it for work, so it means I get paid to learn it. The downside is it’s also work that’s the reason I don’t have the time I need to learn it quickly or properly
Ah well, we can’t have it all ways.
Do you have the book "Numerical Recipes In C" or another variant? That might be useful.
My final year engineering project has been an arbitrary precision (integer) arithmetic library in the Residue Number System (written in C). It's almost complete. RNS is another numerical technique you might want to have some fun with.
KupoTony (post: 1269926) wrote:I know guys this might sound for you very newbie,but.......does anyone know a simple step-by-step Algorithm for RNGs,and RBGs,without using functions that already has the ability to display random numbers,(in Basic,TI-83+ is rand,randint(),randnm())......and can anyone show me the sketch of a Seed,and how to make one,and a randomnumberfunction,in just hardcore algorithms,not functions with related capabilities,can you show it in Java and explain it.....
Users browsing this forum: No registered users and 130 guests