tag:blogger.com,1999:blog-76653892501967926572024-03-12T22:53:13.263-04:00Everything TechnologyPosting about my life and technology. From nazi zombies to programming to software to operating systems.JRhttp://www.blogger.com/profile/17256901791915935327noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-7665389250196792657.post-36167224870101018482011-02-15T00:09:00.000-05:002011-02-15T00:09:10.397-05:00Temperature Conversion - The C Way#include <stdio.h><br />
<br />
#define LOWER 0 /* lower limit of table */<br />
#define UPPER 300 /* upper limit */<br />
#define STEP 20 /* step size */<br />
<br />
/* print Fahrenheit-Celsius table */<br />
<br />
main()<br />
{<br />
int fahr;<br />
<br />
for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP)<br />
printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));<br />
}<br />
<br />
Using Symbolic Constraints we are not throwing magic numbers into the program. This method makes it a lot easier to hand this code off to another programmer he can jump right into editing it even without a synopsis of what it does. Not nearly as complicated as the encryption program but this is where I am at so its cool. I am almost on chapter two of my C Programming book!JRhttp://www.blogger.com/profile/17256901791915935327noreply@blogger.com43tag:blogger.com,1999:blog-7665389250196792657.post-24870040245211732612011-02-13T00:28:00.001-05:002011-02-13T00:29:02.967-05:00Encrypt-a-file //**************************************<br />
//INCLUDE files for :crypt.c<br />
//**************************************<br />
#include <stdio.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
#include <fcntl.h><br />
//**************************************<br />
// Name: CryptCode.c<br />
// Description:Encrypts file and outputs it to a file or stdout<br />
// By:Praveena M<br />
//<br />
//<br />
// Inputs:CryptCode.exe <infile> <outfile> <key><br />
//<br />
//**************************************<br />
<br />
#define cypherbits 256 /* encryption strength in bits */<br />
#define cypher cypherbits/(sizeof(int)*8)<br />
int seed[cypher];<br />
void modseed() {<br />
int x;<br />
for(x=1;x<cypher;x++)seed[x]=seed[x]*0x81772012+seed[x]+0x49122035+seed[x+1];<br />
for(x=1;x<cypher;x++)seed[0]=seed[0]^seed[x];<br />
}<br />
int seedsum() {<br />
int n,x;<br />
n=0x80379251;<br />
for(x=0;x<cypher;x++)n=n^seed[x];<br />
return((n>>24)^((n>>16)&255)^((n>>8)&255)^(n&255));<br />
}<br />
char strequ(char *s1,char *s2) {<br />
int p;<br />
p=0;<br />
while((s1[p]==s2[p])&&(s1[p]!=0)&&(s2[p]!=0))p++;<br />
if(s1[p]==s2[p])return(1); else return(0);<br />
}<br />
int main(int argc,char *argv[]) {<br />
char<br />
banner[]="\x43\x6f\x64\x65\x64\x20\x62\x79\x20\x50\x72\x61\x76\x65\x65\x6e\x61"<br />
"\x20\x6f\x66\x20\x49\x6e\x64\x69\x61"<br />
<br />
"\x20\x28\x70\x76\x6e\x63\x61\x64\x40\x6b\x72\x65\x63\x2e\x65\x72\x6e\x65\x74\x2e\x69\x6e\x29";<br />
char buf[2048];<br />
int p,r,l,i,t,s,x;<br />
char b,c,pct,lpct;<br />
FILE *infile=NULL,*outfile=NULL;<br />
fprintf(stderr, "%s\n", banner);<br />
if(argc!=4){<br />
fprintf(stderr,"use: %s <infile> <outfile> <key>\n",argv[0]);<br />
return -1;<br />
}<br />
if(strequ(argv[1],"stdin"))infile=stdin; else<br />
if((infile=fopen(argv[1],"r"))==NULL){<br />
fprintf(stderr,"failed to open %s\n",argv[1]);<br />
return -1;<br />
}<br />
if(strequ(argv[2],"stdout"))outfile=stdout; else<br />
if((outfile=fopen(argv[2],"w"))==NULL){<br />
fprintf(stderr,"failed to create %s\n",argv[2]);<br />
return -1;<br />
}<br />
if(infile!=stdin) {<br />
fseek(infile,0,SEEK_END);<br />
l=ftell(infile);<br />
rewind(infile);<br />
} else l=0;<br />
s=l;<br />
t=0;<br />
pct=0;<br />
if(l<1)fprintf(stderr,"Encrypting data.. (%d bit cypher)\n",cypher*sizeof(int)*8);<br />
else fprintf(stderr,"Encrypting %d bytes.. (%d bit cypher)\n",l,cypher*sizeof(int)*8);<br />
/* bzero(seed,sizeof(seed)); */<br />
modseed();<br />
p=0;<br />
while(argv[3][p]!=0){<br />
modseed();<br />
seed[0]=seed[0]+argv[3][p];<br />
modseed();<br />
p++;<br />
}<br />
i=0;<br />
if(l>0){<br />
fputc('[',stderr);<br />
x=(l/sizeof(buf));<br />
if(l-x*sizeof(buf)!=0)x+=1;<br />
if(x>38)x=38;<br />
for(p=0;p<x;p++) fputc(32,stderr);<br />
fputc(']',stderr);<br />
fputc(13,stderr);<br />
fputc('[',stderr);<br />
fflush(stderr);<br />
}<br />
c=1;<br />
while(c){<br />
r=fread(&buf,1,sizeof(buf),infile);<br />
if(r>0) {<br />
t+=r;<br />
if(l>0){<br />
lpct=pct;<br />
pct=t/(l/x);<br />
if(pct>lpct) {<br />
fputc(88+32*i,stderr); <br />
fflush(stderr);<br />
i=1-i;<br />
}<br />
} else {<br />
fputc(88+32*i,stderr);<br />
fflush(stderr);<br />
i=1-i;<br />
}<br />
p=0;<br />
while(p<r) {<br />
modseed();<br />
buf[p]=buf[p]^seedsum();<br />
p++;<br />
}<br />
if(fwrite(&buf,1,r,outfile)!=r) {<br />
fprintf(stderr,"\nerror writing data\n");<br />
return -1;<br />
}<br />
} else c=0;<br />
}<br />
if(l>0)fputc(']',stderr);<br />
fprintf(stderr,"\nDone. Wrote %d bytes.\n",t);<br />
}<br />
<br />
Okay so I have been checking out this code and all I can say is wow and I can't wait until I get to this level. The formatting got nuked when I copied it into the post editor but looks great in Visual Studio 10. It provides 256 bit encryption and while I am not up on this enough to go into how secure it is I have really enjoyed examining the code. File goes in with a key and out comes the encrypted form. Much thanks goes out to the author.JRhttp://www.blogger.com/profile/17256901791915935327noreply@blogger.com42tag:blogger.com,1999:blog-7665389250196792657.post-34029033738976718692011-02-12T01:10:00.000-05:002011-02-12T01:10:54.955-05:00Feeling LazyAlright so I haven't been very productive today so no blurb about my C programming endeavors. But I am in need of a new mouse. I have been using the same Razer diamondback mouse for years now. Thanks to everyone who gave me input on whether I should with an xbox360 or PS3, now please help me pick a new mouse.<br />
<br />
<br />
<div style="color: #636669; font-family: helvetica, arial, sans-serif; line-height: 15px;"><span class="Apple-style-span" style="font-size: large;"><a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16826104261">Logitech G9x</a></span></div><div style="color: #636669; font-family: helvetica, arial, sans-serif; line-height: 15px;"><br />
</div><div style="font-family: helvetica, arial, sans-serif; line-height: 15px;"><span class="Apple-style-span" style="font-size: x-small;">5700 DPI</span></div><div style="font-family: helvetica, arial, sans-serif; line-height: 15px;"><span class="Apple-style-span" style="font-size: x-small;">Laser Tracking</span></div><div><span class="Apple-style-span" style="font-size: x-small;"><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif;"><span class="Apple-style-span" style="line-height: 15px;">Interchangeable Grips</span></span></span></div><div><span class="Apple-style-span" style="font-size: x-small;"><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif;"><span class="Apple-style-span" style="line-height: 15px;"><br />
</span></span></span></div><div><span class="Apple-style-span" style="font-size: x-small;"><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif;"><span class="Apple-style-span" style="line-height: 15px;"><br />
</span></span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif;"><span class="Apple-style-span" style="line-height: 15px;"><span class="Apple-style-span" style="font-size: large;"><a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16826104178">Logitech MX 518</a></span></span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif;"><span class="Apple-style-span" style="line-height: 15px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;">1800 DPI</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;">Optical Tracking</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;">Sculpted Comfort Grip</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif;"><span class="Apple-style-span" style="line-height: 15px;"><span class="Apple-style-span" style="font-size: large;"><a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16826153056">Razer ABYSSUS</a></span></span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif;"><span class="Apple-style-span" style="line-height: 15px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;">3500 DPI</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;">Optical Tracking</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;">Ultra-Large None Slip Buttons</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 15px;"><br />
</span></span></div><div><span class="Apple-style-span" style="font-family: helvetica, arial, sans-serif;"><span class="Apple-style-span" style="line-height: 15px;">I have been looking at those three and have included a couple specifications for each but feel free to let me know what you are using, are planning to buy, or is your dream mouse.</span></span></div>JRhttp://www.blogger.com/profile/17256901791915935327noreply@blogger.com21tag:blogger.com,1999:blog-7665389250196792657.post-48725901654138294712011-02-11T00:52:00.000-05:002011-02-11T00:52:05.851-05:00Hello World!<u>C Programming Blurb:</u><br />
The book I will be working out of is <u>The C Programming Language</u> (Second Edition) by Brian W. Kernighan and Dennis M. Ritchie. I am starting in the beginning of the book (a novel idea right?) even though I already know the basics I figure it can't really hurt too much to brush up on some things. I am really liking how this book doesn't waste time and gets right to the point. I will be using my laptop running slackware to compile my code.<br />
<br />
<br />
So far in the first chapter my favorite part is the ability to use <i>%d</i> as a placeholder for integer arguments when using the <i>printf</i> output function. So <i>printf("%3d %6d\n", fahr, celsius);</i> formats the variables with right-justified fields creating a lean and clean output statement. In that code snip-it it sets up the <i>fahr</i> variable to be three digits wide and the <i>celsius</i> variable to be six digits width.<br />
<br />
<u>Question of the Day:</u><br />
I am thinking about buying a console for my room. My roommate has an XBOX360 in our basement so I am leaning towards a PS3, but I have always been an XBOX fanboy. So maybe I would want another one just in case he is using his. Any input would be much appreciated.JRhttp://www.blogger.com/profile/17256901791915935327noreply@blogger.com22tag:blogger.com,1999:blog-7665389250196792657.post-26963455232069635432011-02-09T22:15:00.000-05:002011-02-09T22:15:55.002-05:00Fun with CHonestly it feels like its been ages since I have done anything productive on a computer. So in an attempt to turn all that around I am going to get back into programming, even if its doing absolutely stupid simple shit that has no real world application. So I have fucked with Assembly, BASIC, C, C++, Perl, Python, and probably some others. But I have never learned the ins and outs of anything, so I have decided to go with C. Hopefully I will be posting some code I have written shortlyJRhttp://www.blogger.com/profile/17256901791915935327noreply@blogger.com19tag:blogger.com,1999:blog-7665389250196792657.post-13227315213827972922011-02-09T21:43:00.000-05:002011-02-09T21:43:14.225-05:00Why?Alright. So I am giving this whole blogging thing a shot. I hope to add content daily regarding anything and everything I am doing in terms of technology, even if its something as stupid as playing nazi zombies all dayJRhttp://www.blogger.com/profile/17256901791915935327noreply@blogger.com4