pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C++ pastebin - collaborative debugging tool View Help


Posted by notme on Sat 24 May 12:02
report abuse | download | new post

  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. char generateChecksum(string s) {
  7.     int checks = 0;
  8.     for (int i=0; i <s.length(); i++) {
  9.         int nr = (s[i] - 0x30);
  10.         if (i % 3 == 0) checks += (7 * nr);
  11.         if (i % 3 == 1) checks += (3 * nr);
  12.         if (i % 3 == 2) checks += nr;
  13.     }
  14.     char ret = (checks % 10) + 0x30;
  15.     return ret;
  16. }
  17.  
  18. int main()
  19. {
  20.     string base     = "7881738905";
  21.     string birth    = "";
  22.     string expire   = "";
  23.  
  24.     cout    << "Geburts (yymmdd):";
  25.     cin     >> birth;
  26.     cout    << endl;
  27.  
  28.     cout    << "Ablauf (yymmdd):";
  29.     cin     >> expire;
  30.     cout    << endl;
  31.  
  32.     string subfinal = base + birth + generateChecksum(birth) + expire + generateChecksum(expire);
  33.     string final    = base + "D << " + birth + generateChecksum(birth) + " < " + expire + generateChecksum(expire) + " <<<<<<< " + generateChecksum(subfinal);
  34.  
  35.     cout << "Personalausweisnummer:\n" << final;
  36. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me