rendered paste body// Rot-X.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cctype>
#include <stdlib.h>
#include <algorithm>
using namespace std;
string strlower(string s) {
//string hello = "Hello World";
//std::transform(hello.begin(), hello.end(), hello.begin(), (int(*)(int))std::tolower);
std::transform(s.begin(), s.end(), s.begin(), (int(*)(int))std::tolower);
return s;
}
/*FINISHED*/
/*This version of rot requires the number to rot by*/
string rot(int rotNum, string theString) {
if (rotNum == 0)
{ return theString; }
theString = strlower(theString); //string to lowercase
int theStringLen = theString.length();
int asciiValue = 0;
int wrapAdd = 0;
for (int loopNum = 0; loopNum < theStringLen; ++loopNum) {
asciiValue = theString[loopNum] + rotNum;
if (asciiValue > 122) {
wrapAdd = asciiValue - 122;
asciiValue = 96 + wrapAdd;
}
theString[loopNum] = char (asciiValue);
asciiValue = 0;
wrapAdd = 0;
}
return theString;
}
/*This version of rot prints a table for each rot*/
void rotTbl(string theString) {
cout << "Cipher\t|\tResult\n";
cout << "------\t|\t------\n";
string originalString = theString;
for (int loopNum = 0; loopNum < 26; ++loopNum) {
theString = originalString;
cout << "Rot-" << loopNum << "\t|\t" << rot(loopNum, theString) << "\n";
}
}
int _tmain(int argc, _TCHAR* argv[])
{
string awesomeString;
cout <<
"ROT-X VERSION 1.0\n" <<
"By Tommy Boyt\n" <<
"Not distributed under any sort of license yet...\n" <<
"Input the number to be put through the rotational cipher: ";
cin >> awesomeString;
rotTbl(awesomeString);
system("pause");
}