Rotating bits, one shift at a time.
Code
I write a lot of code.
User Handling, part 1
Aug 11th
Intro
At the end of my last post, we had just finished authenticating that a user registering for your site was in fact, a human. Now we’re gonna go a step further and discuss registering them, and creating a simple login system that uses form-based authentication, or more specifically, a form-based authentication system that uses html and http.
Regulating Real Registrations
Jun 8th
It is not all that uncommon for various people to get users registering for whichever website they run. Sometimes it’s one every couple of days or weeks, or sometimes multiple registrations per minute. The one thing the entire spectrum has to deal with though, is making sure the user is a person, someone who types in the name, password, and extra details. Granted if the “hacker” is rich enough, they can get other real people to log in and start spamming links or try to be a scam artist, asking for someone’s password and all that other good stuff. Here are a few unobtrusive ways to help prevent these things from happening.
Star Wars offshoot as a programming concept?
Mar 12th
A couple days ago I was working on some homework for one of my programming classes. We’re learning to program Android OS phones using Java and this particular exercise had us learning how to interact with a SQLite database. Looking through the tutorial of this there was mentioning of “giving basic CRUD functionality” to the system through this Database Adapter that had been written for us.
The ADFGVX Cipher
Jan 23rd
The first in a series of many blog posts I hope to be making as I go on an adventure of learning Cryptography through Programming. Today’s entry is about the ADFGVX cipher, used in World War 1, and first used by me because it was the first on the list.
ore-may ig-pay atenizing-lay
Dec 7th
I got bored. So sue me. Redone in C++ (correctly this time, and probably more efficient than this or this.)
#include <iostream> #include <string> #include <vector> #include <cctype> using namespace std; bool isPunctuation( char c ); string latinize( string s ); bool isVowel( char c ); int main( ) { string input, output, temp; vector<string> words; vector<char> punctuation; cout< < "Enter a phrase you would like to latenize" << endl << "-> "; getline( cin, input ); for( int i = 0; i < input.length(); i++ ) { char c = tolower( input.at( i ) ); if( isPunctuation( c ) ) { words.push_back( temp ); punctuation.push_back( c ); temp.clear(); } else temp.append( 1, c ); } if( !temp.empty() ) { words.push_back( temp ); punctuation.push_back( ' ' ); } for( int i = 0; i < words.size(); i++ ) { string l = latinize( words.at( i ) ); output.append( l ); output.append( 1, punctuation.at( i ) ); } cout<< output << endl; return 0; } bool isPunctuation( char c ) { char punctuation[33] = { ',', '.', '/', '<', '>', '?', ';', '\'', ':', '"', '[', ']', '\\', '{', '}', '|', '`', '-', '=', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', ' ' }; for( int i = 0; i < 33; i++ ) if( c == punctuation[i] ) return true; return false; } string latinize( string s ) { string postfix, temp; for( int i = 0; i < s.length(); i++ ) { char c = s.at( i ); if( isVowel( c ) ) { postfix.append( "ay" ); temp = s.substr( i ); temp.append( "-" ); temp.append( postfix ); return temp; } else postfix.append( 1, c ); } } bool isVowel( char c ) { char vowels[5] = { 'a', 'e', 'i', 'o', 'u' }; for( int i = 0; i < 5; i++ ) if( c == vowels[i] ) return true; return false; }
Cryptologically Speaking
Dec 3rd
I’ve given myself a quest, a quest to find the most secure method to get a user to register, and login to a site, and make sure it’s still them as they explore. This is both surprisingly simple, just complicated because of the amount of steps involved, but depending on who you host with, could also get quite expensive. More on that later. Now? Onto the technical jargon.
Rotating Bits
Nov 25th
Under normal circumstances, you can only ask for a bit rotation using assembly code, however, it is possible to imitate rotation through code.
First an explanation on rotating, and bits:
Goofy Sort
Nov 18th
You know it’s an easy algorithm to program when you’re done writing it, before the teacher is done explaining it…
b9428b173a875a986ca396c6d4770808051
DiceRoller v2
Apr 21st
I decided my first version wasn’t exactly flexible, so I rewrote it to parse out strings of dice rolls and then roll them.
/* * dice.c * * Created on: Apr 21, 2009 * Author: Mike Sherwood (coolhand2@gmail.com) * Modified on: Nov 18, 2009 * Author: Mike Sherwood (coolhand2@gmail.com) * Changes: Changed the if-series in modifySum * to be a select statement instead. */ #include <stdio .h> #include <time .h> #include <stdlib .h> int rollDice( int, int ); void modifySum( char, int, int* ); int main( int argc, char* argv[] ) { char* diceString = argv[1]; int amount, sides, modifier, sum; char mod; amount = sides = modifier = sum = 0; mod = '\0'; sscanf( diceString, "%dd%d%c%d", &amount, &sides, &mod, &modifier ); sum = rollDice( amount, sides ); printf( "Sum: %d\n", sum ); modifySum( mod, modifier, &sum ); printf( "Total: %d\n", sum ); return 0; } int rollDice( int amount, int sides ) { srand( time(NULL)/2 ); int i, value, sum; for( i = value = sum =0; i < amount; i++ ) { value = ( rand() % sides ) + 1; printf( "Dice %d: %d\n", i + 1, value ); sum += value; } return sum; } void modifySum( char mod, int modifier, int* sum ) { switch( mod ) { case '\0': printf( "No Modification\n" ); break; case '+': printf( "Add %d\n", modifier ); *sum += modifier; break; case '-': printf( "Subtract %d\n", modifier ); *sum -= modifier; break; case '*': case 'x': case 'X': printf( "Multiply %d\n", modifier ); *sum *= modifier; break; case '/': printf( "Divide %d\n", modifier ); *sum /= modifier; break; } return; }
Dice Roller v1
Apr 20th
A bit of C code I russelled up to roll a specific die based off the arguments passed to it through the command line. It’s basically just a random number generator with addition properties.
/* * dice.c * * Created on: Apr 20, 2009 * Author: Mike Sherwood <coolhand2 @gmail.com> */ #include <stdio .h> #include <stdlib .h> #include <time .h> int main( int argc, char* argv[] ) { int number, sides, i, val, sum; number = atoi( argv[1] ); sides = atoi( argv[2] ); val = sum = 0; srand( time( NULL )/2 ); printf( "Rolling: %dd%d\n", number, sides ); for( i = 0; i < number; i++ ) { val = (rand() % sides) + 1; printf( "Dice %d: %d\n", i+1, val); sum += val; } printf( "Sum: %d\n", sum ); return 0; }