Skip to content

Instantly share code, notes, and snippets.

@kishba
Created May 11, 2009 18:50
Show Gist options
  • Select an option

  • Save kishba/110103 to your computer and use it in GitHub Desktop.

Select an option

Save kishba/110103 to your computer and use it in GitHub Desktop.

Revisions

  1. kishba revised this gist May 11, 2009. 1 changed file with 16 additions and 4 deletions.
    20 changes: 16 additions & 4 deletions gistfile1.hpp
    Original file line number Diff line number Diff line change
    @@ -8,16 +8,28 @@ int main() {
    int base_value, encrypted_value, key;
    char c, encrypted_c;

    mystring = "stuff";
    mystring = "This is a long string of characters -- now with more punctuation!";
    key = 1;

    cout << "This program shifts lowercase things over a character!" << endl;

    for (int i=0; i<mystring.size(); i++) {
    c = mystring[i];
    base_value = int(c) - 97;
    encrypted_value = (base_value + key) % 26;
    encrypted_c = char(encrypted_value + 97);

    // capitalize any lowercase characters
    if (c >= 'a' && c <= 'z') {
    c = c - 32;
    }

    if (c >= 'A' && c <= 'Z') {
    base_value = int(c) - 65;
    encrypted_value = (base_value + key) % 26;
    encrypted_c = char(encrypted_value + 65);
    } else {
    base_value = 0;
    encrypted_value = 0;
    encrypted_c = c;
    }

    // print out the current character and ascii value
    cout << c << " (" << base_value << ")" << " -> ";
  2. kishba revised this gist May 11, 2009. 1 changed file with 24 additions and 9 deletions.
    33 changes: 24 additions & 9 deletions gistfile1.hpp
    Original file line number Diff line number Diff line change
    @@ -3,15 +3,30 @@
    using namespace std;

    int main() {

    string mystring;

    mystring = "stuff";
    string mystring;

    int base_value, encrypted_value, key;
    char c, encrypted_c;

    mystring = "stuff";
    key = 1;

    cout << "This program shifts lowercase things over a character!" << endl;

    for (int i=0; i<mystring.size(); i++) {
    cout << mystring[i] << " == " << int(mystring[i]) << " -> ";
    cout << (mystring[i] + 1) << " - " << char(mystring[i] + 1) << "\n";
    }
    for (int i=0; i<mystring.size(); i++) {
    c = mystring[i];
    base_value = int(c) - 97;
    encrypted_value = (base_value + key) % 26;
    encrypted_c = char(encrypted_value + 97);

    // print out the current character and ascii value
    cout << c << " (" << base_value << ")" << " -> ";

    // print out the new character and ascii value
    cout << encrypted_c << " (" << encrypted_value << ")";

    cout << endl;
    }

    return 0;
    return 0;
    }
  3. kishba revised this gist May 11, 2009. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.hpp
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,8 @@ int main() {
    mystring = "stuff";

    for (int i=0; i<mystring.size(); i++) {
    cout << mystring[i] << "\n";
    cout << mystring[i] << " == " << int(mystring[i]) << " -> ";
    cout << (mystring[i] + 1) << " - " << char(mystring[i] + 1) << "\n";
    }

    return 0;
  4. kishba revised this gist May 11, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.hpp
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ int main() {

    mystring = "stuff";

    for (int i=0; i<5; i++) {
    for (int i=0; i<mystring.size(); i++) {
    cout << mystring[i] << "\n";
    }

  5. kishba revised this gist May 11, 2009. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions gistfile1.hpp
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,16 @@
    #include <iostream>
    #include <string>
    using namespace std;

    int main() {

    string mystring;

    string mystring = "stuff";
    for (int i=0; i<mystring.size; i++) {
    cout << mystring[i] << "\n";
    }
    return 0;
    mystring = "stuff";
    for (int i=0; i<5; i++) {
    cout << mystring[i] << "\n";
    }
    return 0;
    }
  6. kishba revised this gist May 11, 2009. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions gistfile1.hpp
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,13 @@
    #include <iostream>
    using namespace std;

    int main() {

    mystring = "stuff";
    string mystring = "stuff";

    for (int i=0; i<mystring.size; i++) {
    echo mystring[i];
    cout << mystring[i] << "\n";
    }

    return 0;
    }
    }
  7. kishba created this gist May 11, 2009.
    10 changes: 10 additions & 0 deletions gistfile1.hpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    int main() {

    mystring = "stuff";

    for (int i=0; i<mystring.size; i++) {
    echo mystring[i];
    }

    return 0;
    }