Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge (Out-of-Date)
New Posts  All Forums:Forum Nav:

Programming Challenge (Out-of-Date) - Page 2  

Poll Results: Are you interested in participating in and/or helping organise and post these programming challenges?

 
  • 100% (2)
    I want to participate.
  • 0% (0)
    I want to contribute by helping posting and organise these challenges.
  • 0% (0)
    I'll only take part if other people are willing to participate.
  • 0% (0)
    I can help and participate - I love programming!
  • 0% (0)
    I do not wish to participate or help.
2 Total Votes  
post #11 of 306
Thread Starter 
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.
Main Rig
(15 items)
 
  
Main Rig
(15 items)
 
  
post #12 of 306
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
Decode:
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."\
");
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."\
";
} 

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;
}
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
post #13 of 306
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]\
Flags: -e Encode [string]\
-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\
"); exit(EXIT_FAILURE);}

   printf("%s\
", string);
}
I wonder if that even compiles
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
post #14 of 306
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() ) != '\
' )
  {
    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\
",key);
  puts("");
  puts("Your request has produced:");
  puts(output);

  return 0;
}
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
GAMR
(15 items)
 
  
CPUMotherboardGraphicsGraphics
6600K ASUS Z170-A ASUS 970 Strix ASUS 970 Strix 
RAMHard DriveHard DriveHard Drive
Crucial Ballistix Elite Samsung 850 EVO Intel 320 6400AAKS 
Hard DriveCoolingMonitorPower
6400AAKS Cooler Master Hyper 212 EVO ASUS VG24QE EVGA SuperNova 650 G2 
CaseMouseMouse Pad
Antec 1200 Razer Abyssus 3.5G QCK+ 
  hide details  
post #15 of 306
Thread Starter 
Ok. The encoder challenge is over. Stay tuned for the next installment. Thanks to everyone that participated.
Main Rig
(15 items)
 
  
Main Rig
(15 items)
 
  
post #16 of 306
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:\
"<<endl;
x=0;
while(x<= (count-2))
{
string[x]=string[x]^key[x];
cout<<string[x];
x++;
}


getch();
return 0;
}
teh_pwnage
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo e6600 L631B120 Asrock Dual X1950XT G.SKill DDR2-800 
Hard DriveOptical DriveOSMonitor
Seagate 320gb Lightscribe Windows XP Samsung SyncMaster 906BW, 19" flat 
PowerCase
Hiper 580W Xion Hydraulic 
  hide details  
teh_pwnage
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo e6600 L631B120 Asrock Dual X1950XT G.SKill DDR2-800 
Hard DriveOptical DriveOSMonitor
Seagate 320gb Lightscribe Windows XP Samsung SyncMaster 906BW, 19" flat 
PowerCase
Hiper 580W Xion Hydraulic 
  hide details  
post #17 of 306
bump
    
CPUGraphicsRAMHard Drive
P8700 - 2.53Ghz GeForce Gt220M 1GB 4 GB DDR2 320GB + WD mybook 320GB 
Optical DriveOSMonitor
DVD RW Win 7 Ultimate 64bit 16 inch 
  hide details  
    
CPUGraphicsRAMHard Drive
P8700 - 2.53Ghz GeForce Gt220M 1GB 4 GB DDR2 320GB + WD mybook 320GB 
Optical DriveOSMonitor
DVD RW Win 7 Ultimate 64bit 16 inch 
  hide details  
post #18 of 306
Man, if I wasn't getting owned by programming projects this semester I'd be all over working on some fun challenges.
It's about time!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 @3.3Ghz Gigabyte EP45-UD3P Sapphire 2900Pro Flashed to XT 4Gb Gskill 1066Mhz PK's 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 320Gb & WD Black 640Gb Lite On Vista Business and VMWare Ubuntu Acer AL2223W 22" 
KeyboardPowerCaseMouse
Ergonomic 4000 Corsair HX 620W CM 690 G5 
  hide details  
It's about time!
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 @3.3Ghz Gigabyte EP45-UD3P Sapphire 2900Pro Flashed to XT 4Gb Gskill 1066Mhz PK's 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 320Gb & WD Black 640Gb Lite On Vista Business and VMWare Ubuntu Acer AL2223W 22" 
KeyboardPowerCaseMouse
Ergonomic 4000 Corsair HX 620W CM 690 G5 
  hide details  
post #19 of 306
Quote:
Originally Posted by kdbolt70 View Post
Man, if I wasn't getting owned by programming projects this semester I'd be all over working on some fun challenges.
Second that. ^^
good enough
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 3ghz Gigabyte GA-EP45-DS3L 9800GT 2x2gb fatility DDR2 1066 
Hard DriveOSMonitorMouse
2 x 74gb raptor raid0 win7 64bit Samsung 245BW Razer 3G diamondback 
Mouse Pad
glass core pad 
  hide details  
good enough
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6600 3ghz Gigabyte GA-EP45-DS3L 9800GT 2x2gb fatility DDR2 1066 
Hard DriveOSMonitorMouse
2 x 74gb raptor raid0 win7 64bit Samsung 245BW Razer 3G diamondback 
Mouse Pad
glass core pad 
  hide details  
post #20 of 306
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.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
This thread is locked  
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge (Out-of-Date)