fork download
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. #include<cstring>
  5. #include<cstdlib>
  6.  
  7. #define MAX_MILLISECONDS_BETWEEN_PRINTS 250
  8. #define MAX_CHARS_TO_READ 10
  9.  
  10. void simulatePause(){
  11. int randomDuration = rand()%MAX_MILLISECONDS_BETWEEN_PRINTS+1;
  12. usleep(1000*randomDuration);
  13. }
  14.  
  15. void printSomeCharsFromFile(std::ifstream& fileStream){
  16.  
  17. std::cout.setf(std::ios::unitbuf);
  18.  
  19. std::string chars;
  20. std::string::size_type lengthOfLine = chars.size();
  21. int pos = 0;
  22.  
  23. if(fileStream){
  24. getline(fileStream, chars);
  25. lengthOfLine = chars.size();
  26. pos = 0;
  27.  
  28. while(pos < lengthOfLine){
  29. simulatePause();
  30. int randomLength = rand()%lengthOfLine+1;
  31. randomLength = (randomLength > MAX_CHARS_TO_READ) ? MAX_CHARS_TO_READ : randomLength;
  32. std::cout << chars.substr(pos,randomLength);
  33. pos += randomLength;
  34. }
  35.  
  36. std::cout << "\n";
  37. }
  38. }
  39.  
  40. void autoPrint(std::ifstream& fileStream){
  41. while(fileStream){
  42. printSomeCharsFromFile(fileStream);
  43. }
  44. }
  45.  
  46. int main(int argc, char** argv){
  47.  
  48. //Instructions are for idiots.
  49. if(argc < 1){
  50. std::cout << "Usage: hacker [filename]" << "\n";
  51. std::cout << "There's no man page, don't bother." << "\n";
  52. return 1;
  53. }
  54.  
  55. std::string file_path(argv[1] ? argv[1] : "");
  56. std::string path = file_path;
  57. std::ifstream inputStream;
  58.  
  59. if(file_path == ""){
  60. std::cout << "-----------------------------------" << "\n";
  61. std::cout << "- Welcome to MovieHacker 1.0 -" << "\n";
  62. std::cout << "-----------------------------------" << "\n\n";
  63.  
  64. std::cout << "Please enter a file to hack with." << "\n\n";
  65. std::cin >> file_path;
  66. }
  67.  
  68. inputStream.open(file_path.c_str());
  69.  
  70. if(!inputStream){
  71. std::cerr << "There's been a fatal error. That file doesn't exist.\n";
  72. std::cerr << "First you will be baked. Then there will be cake." << "\n";
  73. return 3;
  74. }
  75.  
  76. for(int i=0;i<1000;i++){
  77. std::cout << "\n";
  78. }
  79.  
  80. autoPrint(inputStream);
  81. inputStream.close();
  82. std::cout << "\n\n------ ACCESS GRANTED --------" << "\n";
  83.  
  84. return 0;
  85. }
  86.  
  87.  
Runtime error #stdin #stdout 0.01s 2864KB
stdin
Standard input is empty
stdout
-----------------------------------
-   Welcome to MovieHacker 1.0    -
-----------------------------------

Please enter a file to hack with.