|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Programming Challenge
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#11 (permalink) | |||||||||||||
|
Bifford
![]() |
Here is my application. It requires the .NET framework v2. It is very basic, and a little flawed. Enter in a message and press "Encode." You will then have a quasi-secret message that you can send to a friend. All they need to know is what setting you used to encode the message (using the slider at the bottom). Trial and error will of course get you to the appropriate value. This is entended to mostly show the weaknesses of shift encoding. I think when this challenge ends, we will try something more sophisticated.
__________________
Helpful Posts (Hopefully )Overclocker's Calculator Photo Editing - B&W w/Color Accents
Last edited by BFRD : 05-19-07 at 08:06 AM |
|||||||||||||
|
|
|
|
#12 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Here's mine so far, I haven't been able to work on it for the past two days. Its a bit flawed too. I plan to work on it tonight and finish it.
To encode or decode you have to pass in a parameter when you run it. Example: Encode: Code:
perl encode.pl -e Code:
perl encode.pl -d Code:
#!/usr/bin/perl
use warnings;
#if the version of perl you are using is older than
#5.6, then get rid of the line "use warning;" and
#make the first line look like this: #!/usr/bin/perl -w
#array used for encoding and decoding
@code = ("A".."Z", "a".."z"," ",0..9);
$eString = "";
$index = 0;
#setting the shift
print "Enter shift => ";
chop($shift = <STDIN>);
if ($ARGV[0] =~ /[Ee]/) {
print "Enter a word => ";
#getting input and removing newline char.
chop ($word = <STDIN>);
$eString = &shifter ($word, '+');
#writing encoded word to file
open(OUTFILE, ">encode.txt");
print OUTFILE ($eString."\n");
close(OUTFILE);
} elsif ($ARGV[0] =~ /[Dd]/) {
unless (open(INFILE, "encode.txt")){
die("Cannot open the file encode.txt");
}
#reading line from file
$word = <INFILE>;
close(INFILE);
$eString = &shifter ($word, '-');
print $eString."\n";
}
sub shifter {
my ($word, $direction) = @_;
#making the string to an array, w/ one char per index
@wordA = split(//, $word);
#generating the encoded string
for (1..length($word)){
for ($i = 0; $i < @code; ++$i){
if ($wordA[$index] eq $code[$i]){
if($direction eq '+'){
$eString .= $code[$i+$shift];
} else {
$eString .= $code[$i-$shift];
}
}
}
$index++;
}
return $eString;
}
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
Last edited by dangerousHobo : 05-08-07 at 02:18 PM |
||||||||||||||
|
|
|
|
#13 (permalink) | |||||||||||||
|
With great difficulty
![]() |
Let's see if I can write this in a reply message
__________________![]() Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void encode(char *p, int key)
{
if(*p>='a'&&*p<='z')
{
if(*p+key>'z') *p=*p+key-'z'+'0';
else *p=*p+key;
}else if(*p>='A' && *p<='Z')
if(*p+key>'Z') *p=*p+key-'Z'+'a';
else *p=*p+key;
}else if(*p>='0' && *p<='9')
if(*p+key>'9') *p=*p+key-'9'+'A';
else *p=*p+key;
}
}
void decode(char *p, int key)
{
if(*p>='a'&&*p<='z')
{
if(*p-key<'a') *p=*p-key-'a'+'Z';
else *p=*p-key;
}else if(*p>='A' && *p<='Z')
if(*p+key<'A') *p=*p-key-'A'+'9';
else *p=*p+key;
}else if(*p>='0' && *p<='9')
if(*p+key<'0') *p=*p-key-'0'+'z';
else *p=*p+key;
}
}
int main(int argc, char *argv[])
{
int key=3; /* Default encoding/decoding key */
char *string, *p1, mode;
if(argc<3 || argv[1][0] != '-') {printf("Usage: %s [flag] [string]\nFlags: -e Encode [string]\n-d Decode [string]", argv[0]); exit(EXIT_FAILURE);
mode=argv[1][1];
if(argc==4) key=atoi(argv[3]);
strcpy(string, argv[2]);
for(p1=string; *p1; p1++)
if(mode=='e') encode(p1, key);
else if(mode=='d') decode(p1, key);
else{printf("Invalid mode\n"); exit(EXIT_FAILURE);}
printf("%s\n", string);
}
|
|||||||||||||
|
|
|
|
#14 (permalink) | |||||||||||||
|
AMD Overclocker
![]() |
I was bored so I did one that included all ASCII. There might be bugs in it because I'm not testing every case.
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char mode;
char c;
char input[500];
char output[500];
int i = 0;
int key;
puts("Enter your message:");
while( ( c = getchar() ) != '\n' )
{
input[i++] = c;
}
input[i] = '\0';
printf("Do you want to [D]ecode or [E]ncode: ");
scanf("%c", &mode);
if ( mode == 'D' )
{
printf("Enter your key: ");
scanf("%i", &key);
/* Subtract key from each index. */
int count = 0;
int length = strlen(input);
while( count <= length - 1 )
{
char temp = input[count];
temp -= key;
output[count] = temp;
count++;
}
output[count] = '\0';
}
if ( mode == 'E' )
{
printf("Enter your key: ");
scanf("%i", &key);
/* Add key from each index */
int length = strlen(input);
int count = 0;
while( count <= length )
{
char temp = input[count];
temp += key;
output[count] = temp;
count++;
}
output[count] = '\0';
}
puts("");
puts("Your input was:");
puts(input);
puts("");
printf("Your key was: %i\n",key);
puts("");
puts("Your request has produced:");
puts(output);
return 0;
}
|
|||||||||||||
|
|
|
|
|
#15 (permalink) | |||||||||||||
|
Bifford
![]() |
Ok. The encoder challenge is over. Stay tuned for the next installment. Thanks to everyone that participated.
__________________
Helpful Posts (Hopefully )Overclocker's Calculator Photo Editing - B&W w/Color Accents
|
|||||||||||||
|
|
|
|
#16 (permalink) | ||||||||||||
|
Overclocker in Training
|
Wow, this challenge is OLD! but hey, I'm new here so i don't really mind unearthing a dino!
__________________Here's an encrypting program that is a bit simpler than bit shift, and more powerful as well! http://uploader.polorix.net//files/594/encrypt7.exe Tips -change the string "key" to change how it's encrypted -Notice how the decoding, is the same as encoding! It works backwards! -The only encoding occurs in here, everything else is just getting input (poorly i admit) while(x<= (count-2)) { string[x]=string[x]^key[x]; ///XOR check on the binaries cout<<string[x]; x++; } the code #include <iostream.h> #include <stdio.h> #include <string.h> //provides strcat() --adds to end of string #include <conio.h> //provides getch() --gets int for key press int main() { char string[400]=""; char temp[] = "1"; char key[400]="I am the key used for encryption"; int count = 0; cout<<"input string to encrypt or type enter to decode"<<endl; while ((int)temp[0] != 13) //while not key_enter { count++; temp[0] =(char)getch(); strcat(string,temp); cout<<temp; } if (count==1) { count--; temp[0]=1; cout<<"input string to decode: "; while ((int)temp[0] != 13) { count++; temp[0] =(char)getch(); strcat(string,temp); cout<<temp; } cout<<endl<<endl<<"decoded it is: "; } else { cout<<endl<<endl<<"You wrote: "<<string<< endl<<"encrypted it is: "<<endl; } int x=0; while(x<= (count-2)) { string[x]=string[x]^key[x]; ///XOR check on the binaries cout<<string[x]; x++; } cout<<endl<<" Decoded it is:\n"<<endl; x=0; while(x<= (count-2)) { string[x]=string[x]^key[x]; cout<<string[x]; x++; } getch(); return 0; }
|
||||||||||||
|
|
|
|
|
#17 (permalink) | |||||||
|
Audiophile
![]() |
bump
__________________
IF SOMEONE HELPS YOU, HELP THEM! Most people wouldn't know music if it came up and bit them on the ass. ~ Frank Zappa
|
|||||||
|
|
|
|
|
#18 (permalink) | |||||||||||||
|
Programmer
![]() |
Man, if I wasn't getting owned by programming projects this semester I'd be all over working on some fun challenges.
__________________
Whats this folding I've been hearing about? Crucial Ballistix Club ![]() Member of the OCN Diablo III Club ~M Hail to the Victors M~
|
|||||||||||||
|
|
|
|
|
#19 (permalink) | |||||||||
|
Programmer
![]() |
Second that. ^^
__________________
My Lego case thread. With PICS!!! ----------------------------------------------------------------------- Video card RMA database thread. I am working on an application that allows users to input their cards issues into a database, to build a knowledge base for what types of cards have a lower fail rate.
|
|||||||||
|
|
|
|
|
#20 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Yeah, been having one after another.
![]() Not been getting owned, but they are eating up all my time. Right now I have to basically build the TCP protocol out of UDP.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|