1. Си / Говнокод #28865

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    int calculate_2(int op1, int op2, char operator, int memory_smp[],
                    int *count_command) {
    
      int result = 0;
    
      switch (operator) {
      case '+':
    
        memory_smp[*count_command] = (2000 + op1);
        (*count_command)++;
    
        memory_smp[*count_command] = (3000 + op2);
        (*count_command)++;
    
        memory_smp[*count_command] = (2100 + count_down);
    
        (*count_command)++;
        result = count_down;
        count_down--;
    
        // result = op1 + op2;
        break;
      case '-':
        memory_smp[*count_command] = (2000 + op1);
        (*count_command)++;
        memory_smp[*count_command] = (3100 + op2);
        (*count_command)++;
        memory_smp[*count_command] = (2100 + count_down);
        (*count_command)++;
        result = count_down;
        count_down--;
        // result = op1 - op2;
        break;
      case '*':
        memory_smp[*count_command] = (2000 + op1);
        (*count_command)++;
        memory_smp[*count_command] = (3300 + op2);
        (*count_command)++;
        memory_smp[*count_command] = (2100 + count_down);
        (*count_command)++;
        result = count_down;
        count_down--;
        // result = op1 * op2;
        break;
      case '/':
    
        memory_smp[*count_command] = (2000 + op1);
        (*count_command)++;
        memory_smp[*count_command] = (3200 + op2);
        (*count_command)++;
        memory_smp[*count_command] = (2100 + count_down);
        (*count_command)++;
        result = count_down;
        count_down--;
        //   result = op1 / op2;
        break;
      /*
      case '^':
        result = pow(op1, op2);
        break;
      case '%':
        result = op1 % op2;
        break;
      */
      default:
        break;
      }
    
      return result;
    }

    Симлтрон из Дейтелов
    5

    gne4do, 02 Октября 2023

    Комментарии (0)
  2. Си / Говнокод #28864

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    file_buf = fopen(argv[2], "w");
    
      for (d = 0; mem_smp[d] != 0; d++) {
    
        fprintf(file_buf, "%d %d\n", d, mem_smp[d]);
      }
    
      for (d = 0; (symbolTable + d)->type != 'q'; d++) {
    
        if ((symbolTable + d)->type == 'C') {
          count_cmd = atoi((symbolTable + d)->symbol);
    
          fprintf(file_buf, "%d %d\n", (symbolTable + d)->location, count_cmd);
        }
      }
      fclose(file_buf);
    
      return 0;
    }
    
    int past_in_table_cons_or_value(data *table, char *str_tok) {
    
      int search_in_table(data * intro_search, char *str_tok_search);
    
      int find = search_in_table(table, str_tok);
    
      if ((table + find)->type == 'q') {
    
        if (my_isalpha(*str_tok)) {
          (table + find)->symbol[0] = *str_tok; //  or  str_tok don't atoi
    
        } else {
          strcpy((table + find)->symbol, str_tok);
        }
    
        (table + find)->type = my_isalpha(*str_tok) ? 'V' : 'C';
    
        (table + find)->location = count_down;
    
        count_down--;
      }
    
      return (table + find)->location;
    }
    
    int evaluatePostfixExpression_2(char *expr, int memory_smp[],
                                    int *count_command) {
      StackNodePtr_2 stackPtr = NULL;
      char c;
      int x, y;
      int i = 0, mult = 1, num = 0;
    
      while (expr[i] != '\0') {
        mult = 1;
        num = 0;
        c = expr[i];
        if (my_isdigit(c)) {
          while (my_isdigit(c)) {
            num *= mult;
            num += c - 48;
            c = expr[++i];
            mult *= 10;
          }
          --i;
          push_2(&stackPtr, num);
        } else if (isOperator_2(c)) {
          if (isEmpty_2(stackPtr)) {
            printf("Invalid postfix expression!\n");
            return 0;
          }
          x = pop_2(&stackPtr);
    
          if (isEmpty_2(stackPtr)) {
            printf("Invalid postfix expression!\n");
            return 0;
          }
          y = pop_2(&stackPtr);
    
          push_2(&stackPtr, calculate_2(y, x, c, memory_smp, &(*count_command)));
        }
        i++;
      }
    
      if (isEmpty_2(stackPtr)) {
        printf("Invalid postfix expression!\n");
        return 0;
      }
    
      return pop_2(&stackPtr);
    }
    
    int calculate_2(int op1, int op2, char operator, int memory_smp[],
                    int *count_command) {
    
      int result = 0;

    Симплтрон из задачи Дейтелов
    4

    gne4do, 02 Октября 2023

    Комментарии (0)
  3. Си / Говнокод #28863

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    if (sign_ch == 0) {
              swp = val_if[0];
              val_if[0] = val_if[1];
              val_if[1] = swp;
            }
    
            mem_smp[count_cmd] = 2000 + (symbolTable + val_if[1])->location;
            count_cmd++;
            mem_smp[count_cmd] = 3100 + (symbolTable + val_if[0])->location;
            count_cmd++;
    
            if (goto_flag == 1) {
              flags[count_cmd] = second_buf;
              mem_smp[count_cmd] = rn_data[ab].data[0];
              count_cmd++;
            } else {
              mem_smp[count_cmd] = rn_data[ab].data[0] + second_buf;
              count_cmd++;
            }
    
            if (rn_data[ab].type == 2) {
    
              mem_smp[count_cmd] = 2000 + (symbolTable + val_if[0])->location;
              count_cmd++;
              mem_smp[count_cmd] = 3100 + (symbolTable + val_if[1])->location;
              count_cmd++;
    
              if (goto_flag == 1) {
                flags[count_cmd] = second_buf;
                mem_smp[count_cmd] = rn_data[ab].data[1];
                count_cmd++;
              } else {
                mem_smp[count_cmd] = rn_data[ab].data[1] + second_buf;
                count_cmd++;
              }
            }
    
          }
    
          else if (my_strcmp(buffer, "goto") == 0) {
    
            second_buf = 0;
            goto_flag = 0;
    
            intro_buffer = strtok(NULL, " ");
            second_buf = goto_search(symbolTable, intro_buffer);
    
            if (second_buf == 0) {
              second_buf = atoi(intro_buffer);
              goto_flag = 1;
            }
    
            if (goto_flag == 1) {
              flags[count_cmd] = second_buf;
              mem_smp[count_cmd] = 4000;
              count_cmd++;
            } else {
              mem_smp[count_cmd] = 4000 + second_buf;
              count_cmd++;
            }
          }
    
          else if (my_strcmp(buffer, "print") == 0) {
            intro_buffer = strtok(NULL, " ");
            second_buf = search_in_table(symbolTable, intro_buffer);
            mem_smp[count_cmd] = 1100 + (symbolTable + second_buf)->location;
            count_cmd++;
    
          }
    
          else if (my_strcmp(buffer, "input") == 0) {
            intro_buffer = strtok(NULL, " ");
            past_in_table_cons_or_value(symbolTable, intro_buffer);
            second_buf = search_in_table(symbolTable, intro_buffer);
            mem_smp[count_cmd] = 1000 + (symbolTable + second_buf)->location;
            count_cmd++;
          } else if (my_strcmp(buffer, "end") == 0) {
    
            mem_smp[count_cmd] = 4300;
          }
    
          ////////////////////////////////////////////////////////////////////////
          count_table_extra = count_cmd;
          /////////////////////////////////////////////////////////////////////////
        }
      }
    
      for (d = 0; mem_smp[d] != 0; d++) {
        if (flags[d] != -1) {
    
          sprintf(&postfix[0], "%d", flags[d]);
    
          goto_flag = search_in_table(symbolTable, postfix);
          mem_smp[d] += (symbolTable + goto_flag)->location;
        }
      }

    Симплтрон из задачи Дейтелов
    3

    gne4do, 02 Октября 2023

    Комментарии (0)
  4. Си / Говнокод #28862

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    int second_buf = 0;
    
      for (; d != 100; d++) {
    
        strcpy((symbolTable + d)->symbol, "0");
        (symbolTable + d)->location = 0;
        (symbolTable + d)->type = 'q';
        mem_smp[d] = 0;
        flags[d] = -1;
      }
    
      printf("%s\n", argv[0]);
    
      file_buf = fopen(argv[1], "r");
    
      for (d = 0; feof(file_buf) == 0; ++d) {
    
        fgets(&buf_data[d][0], 150, file_buf);
      }
    
      fclose(file_buf);
    
      memcpy(copy_buf_data, buf_data, sizeof(char) * 150 * 150);
    
      for (d = 0; buf_data[d][0] != 0; d++) {
    
        buffer = strtok(&buf_data[d][0], " ");
    
        for (; buffer != NULL; buffer = strtok(NULL, " ")) {
    
          if (token_string_count == 0 && my_isdigit(*buffer)) {
    
            count_table_intro = search_in_base(symbolTable, buffer);
    
            strcpy((symbolTable + count_table_intro)->symbol, buffer);
    
            (symbolTable + count_table_intro)->type = 'L';
    
            (symbolTable + count_table_intro)->location = count_table_extra;
          }
    
          if (rem_break(buffer) == 1) {
    
            (symbolTable + count_table_intro)->location = count_table_extra;
    
            break;
          }
    
          else if (my_strcmp(buffer, "let") == 0) {
    
            strcpy(infix, &copy_buf_data[d][7]);
            convertToPostfix_1(infix, postfix);
            save_left_side = let_past(symbolTable, postfix, post_buf);
    
            save_exp = evaluatePostfixExpression_2(post_buf, mem_smp, &count_cmd);
            mem_smp[count_cmd] = (2000 + save_exp);
            count_cmd++;
    
            mem_smp[count_cmd] = (2100 + save_left_side);
            count_cmd++;
    
          }
    
          else if (my_strcmp(buffer, "if") == 0) {
    
            strcpy(infix, &copy_buf_data[d][5]);
            intro_buffer = strtok(infix, " ");
            second_buf = 0;
            for (count_if = 0, sign_ch = 1, ab = 0; intro_buffer != (char *)'\0';
                 intro_buffer = strtok(NULL, " "), count_if++) {
    
              if (!my_strcmp(intro_buffer, "goto")) {
                goto_flag = 0;
                intro_buffer = strtok(NULL, " ");
    
                second_buf = goto_search(symbolTable, intro_buffer);
    
                if (second_buf == 0) {
                  second_buf = atoi(intro_buffer);
                  goto_flag = 1;
                }
    
              }
    
              else if (strstr(comparison_signs, intro_buffer)) {
                ab = intro_buffer[0] + intro_buffer[1];
    
                sign_ch = !(ab == 60);
    
              }
    
              else if ((isalnum(*intro_buffer))) {
    
                past_in_table_cons_or_value(symbolTable, intro_buffer);
    
                val_if[cnt++] = search_in_table(symbolTable, intro_buffer);
              }
            }

    Симплтрон из задачи Дейтелов
    2

    gne4do, 02 Октября 2023

    Комментарии (0)
  5. Си / Говнокод #28861

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    #include <ctype.h>
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int evaluatePostfixExpression_2(char *, int memory_smp[], int *count_command);
    int calculate_2(int, int, char, int memory_smp[], int *count_command);
    
    typedef struct mode_intro {
      int type;
      int data[2];
    
    } expr_if;
    
    int main(int argc, char *argv[]) {
    
      expr_if rn_data[125];
    
      /*  !=   */
      rn_data[94].type = 2;
      rn_data[94].data[0] = 4100;
      rn_data[94].data[1] = 4100;
      /*  !=   */
    
      /*  ==   */
      rn_data[122].type = 1;
      rn_data[122].data[0] = 4200;
      /*  ==   */
    
      /*  <=   */
      rn_data[121].type = 2;
      rn_data[121].data[0] = 4200;
      rn_data[121].data[1] = 4100;
      /*  <=   */
    
      /* < Øèâîðîò íà âûâîðîò  */
      rn_data[60].type = 1;
      rn_data[60].data[0] = 4100;
      /*  <   */
    
      /*  >=   */
      rn_data[123].type = 2;
      rn_data[123].data[0] = 4200;
      rn_data[123].data[1] = 4100;
      /*  >=   */
    
      /* > */
      rn_data[62].type = 1;
      rn_data[62].data[0] = 4100;
      /* > */
    
      char infix[150];
      char postfix[150];
    
      int line_simple_comands_input_print(int cmd, data *table, int token,
                                          int memory[]);
    
      int past_in_table_cons_or_value(data * table, char *str_tok);
      int ab = 0;
      int swp = 0;
      int goto_search(data * table, char *token);
    
      int search_cmd(char *dict[15], char *token);
      char *comparison_signs = "> < <= >= == !=";
      int token_string_count = 0;
      data symbolTable[100];
    
      int cnt = 0;
      int d = 0;
      int count_if = 0;
      int flags[100];
    
      int mem_smp[100];
      char copy_buf_data[150][150] = {{0}};
      char post_buf[150];
      int count_cmd = 0;
    
      int sign_ch;
      FILE *file_buf;
    
      char *buffer = 0;
      char *intro_buffer = 0;
      int save_left_side = 0, save_exp = 0;
      int goto_flag = 0;
    
      int count_table_intro = 0;
      int count_table_extra = 0;
      char name_file[100];
    
      char buffer_postfix[150];
      char buf_data[150][150] = {{0}};
      int val_if[3] = {0};
    
      int data_if[150] = {0};
    
     data_if[60] = 4100;
     data_if[61] = 1;

    Симплтрон из задачи по Дейтелам
    1

    gne4do, 02 Октября 2023

    Комментарии (1)
  6. Си / Говнокод #28834

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    static inline int is_openvpn_handshake(const char *pktdata, unsigned int pktlen) {
        /*
         * 0x38 is P_CONTROL_HARD_RESET_CLIENT_V2 + peer_id(0),
         * 0x50 is P_CONTROL_HARD_RESET_CLIENT_V3 + peer_id(0)
         */
        return pktlen >= 16
               && ntohs(((uint16_t*)pktdata)[0]) == pktlen - 2
               && (pktdata[2] == '\x38' || pktdata[2] == '\x50');
    }

    Код обнаружения протокола OpenVPN по рукопожатию.

    ropuJIJIa, 10 Августа 2023

    Комментарии (45)
  7. Си / Говнокод #28798

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    struct node
    {
        void *data;
    
        struct node *head;
        struct node *tail;
    };
    struct list
    {
        int size;
    
        struct node *head;
        struct node *tail;
    
        void *(*alloc_node)(size_t);
        void *(*alloc_data)(size_t);
        void (*free_node)(void *);
        void (*free_data)(void *);
    };
    
    typedef struct node node_t;
    typedef struct list list_t;
    
    void list_init(list_t *list)
    {
        list->size = 0;
    
        list->head = (node_t*)list;
        list->tail = (node_t*)list;
    
        list->alloc_node = &malloc;
        list->alloc_data = &malloc;
        list->free_node = &free;
        list->free_data = &free;
    }
    void list_link(struct node *head, struct node *tail)
    {
        head->tail = tail;
        tail->head = head;
    }
    void *push_head(list_t *list, node_t *head, size_t size)
    {
        node_t *node = list->alloc_node(sizeof(node_t));
        void   *data = list->alloc_data(size);
    
        node->data = data;
        list_link(node, head->tail);
        list_link(head, node);
    
        list->size++;
        return data;
    }
    void *push_tail(list_t *list, node_t *tail, size_t size)
    {
        node_t *node = list->alloc_node(sizeof(node_t));
        void   *data = list->alloc_data(size);
    
        node->data = data;
        list_link(tail->head, node);
        list_link(node, tail);
    
        list->size++;
        return data;
    }
    void pop(list_t *list, node_t *node)
    {
        list_link(node->head, node->tail);
        list->size--;
    
        void *data = node->data;
    
        list->free_node(node);
        list->free_data(data);
    }
    void print(struct list *list)
    {
        printf("\n====\n");
    
        printf("size: %ld \n", list->size);
    
        int i = 0;
    
        for(node_t *node = list->head; node != list; node = node->head)
        {
            printf("index: %ld number: %ld \n", i, *(int*)(node->data));
            i++;
        }
    }
    
    struct list lst;
    
        list_init(&lst);
    
        print(&lst);
    
        void *data;
        data = push_tail(&lst, lst.tail, 4);
        *(int*)data = 1;

    итак скажите про название функций про то каких функций не хватает + alloc и free поля не трогать это мне нужно ТОЛЬКО НЕ советуйте перейти на с++ и использовать чтото другое(std::list)

    CodeTux, 16 Июня 2023

    Комментарии (23)
  8. Си / Говнокод #28745

    0

    1. 1
    2. 2
    printf ("%d file%s processed", nfiles,
            nfiles != 1 ? "s" : "");

    Из официального гайда "GNU" по написанию кода на "C".

    JloJle4Ka, 17 Апреля 2023

    Комментарии (1005)
  9. Си / Говнокод #28643

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    void PasswordChecker(void);
    void sub_BB4F(unsigned char* Password);//subroutine $BB4F and so on...
    void sub_BB21(void);
    void sub_BBE0(void);
    void sub_BBEA(void);
    void SEC_SBC_6502(unsigned char operand);
    void ADC_6502_simplified(unsigned char operand);
    unsigned char Password[8];//$0766 to $076D in RAM, when a player enters it
    unsigned char Invalidity=0;//$0764 in RAM
    unsigned char Level;//$$0070 in RAM
    unsigned char TimeTens;//$04c5 in RAM
    unsigned char TimeOnes;//$04c6 in RAM
    unsigned char Byte4BF, Byte17, Byte18;
    unsigned char a, x;
    unsigned char c=0;//carry flag
    //former char Byte76A is Password[4] now, former char Byte76C is Password[6] now
    
    void PasswordGenerator(void);
    void BuildORTable(void);
    unsigned char* BuildParticularLevelsArray(unsigned char DesiredLevel);//will think of it later...
    void SimplifiedLevelGenerator(unsigned char* PassToFill,unsigned char Level);//finds just one 2nd,3rd,6th,8th digit combo
    
    int main()
    {
    	int Choice;
    	printf("Enter g if you'd like to generate a new password.\nEnter a to analyze an existing password.\n");
    	Choice=fgetc(stdin);
    	flushall();
    	if (Choice=='a')
    	PasswordChecker();
    	if (Choice=='g')
    	PasswordGenerator();
    	if (Choice=='s')//'level function' is basic when generating a pass
    	BuildORTable();//so here a bit of 'hidden' investigation, which will be useful
    	//if I ever decide to rewrite this prog to output all passes possible, not just one
    	printf("Press any key to quit.\n");
    	getch();
    	return 0;
    }
    
    void PasswordChecker(void)
    {
    	char InputString[9];//one extra byte needed due to fgets
    	int i;
    	printf("Please enter your password to test:\n");
    	fgets(InputString,9,stdin);
    	for(i=0;i<8;i++)
    	{
    		if ((InputString[i]>57)||(InputString[i]<48))
    		{
    			printf("This string contains non-digits.\n");
    			return;
    		}
    		else
    			Password[i]=InputString[i]-48;//ascii to digit
    	}
    	sub_BB4F(Password);
    	if (Invalidity==1)
    	{
    		printf("This password is invalid.\n");
    		return;
    	}
    	printf("%s%d","Level: ",Level);
    	printf("%s%d%d\n"," Time: ",TimeTens,TimeOnes);
    	if (Level==15)
    	printf("Level 15 doesn't exist. So-called level 15 passwords are programming mistakes and cause system hang.\n");
    	if (Level==16)
    	printf("Level 16 doesn't exist. So-called level 16 passwords are programming mistakes and lead you to a buggy screen where Prince can't move.\n");
    	return;
    }
    
    void sub_BB4F(unsigned char* Password)//$BB4F
    {
    	a=0;
    	x=0;
    	while (x<8)
    	{
    		a=a+Password[x];
    		x++;
    	}
    	if(a==0)
    	{
    		Invalidity=1;//$BBC0
    		return;
    	}
    	Byte17=Password[4];//$BB63
    	Byte18=Password[6];
    	Password[4]=0;
    	Password[6]=0;
    	sub_BB21();//$BB72,calculates and writes 1st checksum to Password[4], 2nd checksum to Password[6]
    	if (Password[4]!=Byte17)
    	{
    		Invalidity=1;
    		return;
    	}

    Генератор паролей для игры Prince Of Perisa. Пришлось немного повозиться...


    if (Password[6]!=Byte18)//$BB7C
    {
    Invalidity=1;
    return;
    }
    Invalidity=0;//$BB85
    a=Password[7];
    sub_BBEA();
    a=a&3;//$BB8E
    a=a*4;
    Password[7]=a;
    a=Password[1];
    sub_BBE0();//$BB98
    a=a|Password[7];
    Level=a+1;//+1 is my insertion
    //if (Level!=1)//I chose to omit this $BBA2-$BBA4 code b/c it's unknown what byte at $06EE means
    a=Password[0];
    sub_BBE0();//$BBAA
    TimeTens=a;
    a=Password[3];
    sub_BBEA();
    TimeOnes=a;
    return;//$BBBF
    }

    void SEC_SBC_6502(unsigned char operand)
    {
    c=1;
    if ((a-operand)>=0)
    a=a-operand;
    else
    {
    a=a-operand+256;
    c=0;
    };
    }

    void ADC_6502_simplified(unsigned char operand)
    {
    if ((a+operand)<256)
    a=a+operand;
    else a=a+operand-256;
    }

    void sub_BB21(void)
    {
    x=0;
    BB23: a=Password[4];
    a=a+Password[x];
    if(a<10)
    {
    BB46: Password[4]=a;//$BB46
    x++;
    if (x!=8)
    goto BB23;
    else return;//$BB4E
    }
    else //$BB2E
    {
    Byte4BF=a;
    a=Password[6];
    a++;//we came here b/c c=1
    if (a<10)
    goto BB3D;
    else
    SEC_SBC_6502(10);//can we get here? I doubt...
    BB3D: Password[6]=a;
    a=Byte4BF;
    SEC_SBC_6502(10);//$BB44, no danger of negative result
    goto BB46;
    }
    }

    cepreu_monoJlb, 19 Марта 2023

    Комментарии (6)
  10. Си / Говнокод #28582

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    int main ()
    {
       char address[128], fname[128], command[128];
       FILE *tempfile;
    
       strcpy(fname , tmpnam(NULL));
       tempfile = fopen (fname, "w");     /* create temporary file */
       if (tempfile == NULL)              /* error - didn't create file */
       {
          printf("Internal failure #1 please report %d\n", errno);
          exit (1);
       }
       fprintf(tempfile, "Thank you very much for caring about our cause\n");
       fprintf(tempfile, "this letter is just to tell you how much we\n");
       fprintf(tempfile, "really think you are wonderful for caring.\n\n");
       fprintf(tempfile, "Sincerely,\n\n");
       fprintf(tempfile, "Jane Doe, Executive Thanker\n");
    fclose (tempfile);
       gets(address);                            /* read in email address */
    
       sprintf(command, "mail -s \"thanks for caring\" %s < %s\n",
               address, fname);                /* create the command */
       system (command);                       /* execute command */
       remove (fname);                         /* clean up */
       exit (0);
    }

    Игра: найди вулна.

    JloJle4Ka, 03 Февраля 2023

    Комментарии (19)