void testSymbol() { #if 0 // Operator int i = 0; for(; i < KeywordsCount; ++i) { printf("%s\n", Operators[i]); } #endif // test: isKeyword isLiteral isVar isSemicolon symbol_construct symbol_deconstruct #if 0 // not ok char *symbol[] = {"int", "i", "=", "12", ";"}; for(int i = 0; i < sizeof(symbol) / sizeof(symbol[0]); ++i) { // ok printf("symbol %s : isKeyword:%s isLiteral:%s isVar:%s isSemicolon:%s\n", symbol[i], TO_BOOL_STR(isKeyword(symbol[i])), TO_BOOL_STR(isLiteral(symbol[i])), TO_BOOL_STR(isVar(symbol[i])), TO_BOOL_STR(isSemicolon(symbol[i]))); Symbol *sb = symbol_construct(symbol[i]); if(sb) { // not ok printf("%x %x %x %x \n", IS_KEYWORD(sb->type), IS_LITERAL(sb->type), IS_VAR(sb->type), IS_SEMICOLON(sb->type)); symbol_deconstruct(sb); } } #endif // test: isCharLiteral isStringLiteral isDecNumber isOctNumber isHexNumber isFloatNumer // tes: isDoubleNumber #if 0 // ok int i = 0; const char *strArr[] = {"\'c\'", "\"abc\"", "453", "0453", "781", "a90", "0x34", "0X56", "9.34", "9.4e2", "9.5E5", "9e+2", "9e-3", "9.34f", "9.34F" }; for(; i < sizeof(strArr) / sizeof(strArr[0]); ++i) { printf("%s: isCharLiteral(%s)\n\t", strArr[i], TO_BOOL_STR(isCharLiteral(strArr[i]))); printf("isStringLiteral(%s)\n\t", TO_BOOL_STR(isStringLiteral(strArr[i]))); printf("isDecNumber(%s)\n\t", TO_BOOL_STR(isDecNumber(strArr[i]))); printf("isOctNumber(%s)\n\t", TO_BOOL_STR(isOctNumber(strArr[i]))); printf("isHexNumber(%s)\n\t", TO_BOOL_STR(isHexNumber(strArr[i]))); printf("isFloatNumber(%s)\n\t", TO_BOOL_STR(isFloatNumber(strArr[i]))); printf("isDoubleNumber(%s)\n", TO_BOOL_STR(isDoubleNumber(strArr[i]))); } /* // I don't know why, but it can't output all strings for(; i < sizeof(strArr) / sizeof(strArr[0]); ++i) { printf("%s: isCharLiteral(%s)\n\t isStringLiteral(%s)\n\t isDecNumber(%s)\n\t isOctNumber(%s)\n\t isHexNumber(%s)\n\t isFloatNumber(%s)\n\t isDoubleNumber(%s)\n", strArr[i], TO_BOOL_STR(isCharLiteral(strArr[i])), TO_BOOL_STR(isStringLiteral(strArr[i])), TO_BOOL_STR(isDecNumber(strArr[i])), TO_BOOL_STR(isOctNumber(strArr[i])), TO_BOOL_STR(isHexNumber(strArr[i])), TO_BOOL_STR(isFloatNumber(strArr[i])), TO_BOOL_STR(isDoubleNumber(strArr[i]))); } */ #endif }
int main(int argc, char* argv[]) { if(argc!=5) { printf("Invalid number of arguments.\n"); return 1; } if(strlen(argv[1])!=16){ printf("Invalid upper key length.\n"); return 2; } if(strlen(argv[2])!=16){ printf("Invalid lower key length.\n"); return 3; } if(strlen(argv[3])!=16){ printf("Invalid plaintext length.\n"); return 4; } if(!isHexNumber(argv[1])||!isHexNumber(argv[2])){ printf("Invalid key format.\n"); return 5; } if(!isHexNumber(argv[3])) { printf("Invalid plaintext format.\n"); return 6; } if(!isNumber(argv[4])) { printf("Invalid input for number of iterations."); return 7; } uint8_t keyBytes[16]; uint64_t subkeys[101]; uint8_t plaintextBytes[8]; hexStringToBytes(keyBytes, argv[1], strlen(argv[1])); hexStringToBytes(keyBytes+8, argv[2], strlen(argv[2])); hexStringToBytes(plaintextBytes, argv[3], strlen(argv[3])); uint64_t numIterations = toLL(argv[4]); generateSubkeys(keyBytes, subkeys); printf("%016llx\n", encrypt(join(plaintextBytes), numIterations, subkeys)); return 0; }
//////////////////////////////////////////////////////////////////////////////// // When a Lexer object is constructed with a string, this method walks through // the stream of low-level tokens. bool Lexer::token (std::string& token, Lexer::Type& type) { // Eat white space. while (isWhitespace (_text[_cursor])) utf8_next_char (_text, _cursor); // Terminate at EOS. if (isEOS ()) return false; // The sequence is specific, and must follow these rules: // - date < duration < uuid < identifier // - dom < uuid // - uuid < hex < number // - url < pair < identifier // - hex < number // - separator < tag < operator // - path < substitution < pattern // - set < number // - word last if (isString (token, type, "'\"") || isDate (token, type) || isDuration (token, type) || isURL (token, type) || isPair (token, type) || isUUID (token, type, true) || isSet (token, type) || isDOM (token, type) || isHexNumber (token, type) || isNumber (token, type) || isSeparator (token, type) || isTag (token, type) || isPath (token, type) || isSubstitution (token, type) || isPattern (token, type) || isOperator (token, type) || isIdentifier (token, type) || isWord (token, type)) return true; return false; }
Token_sub_type getTokenSubTypeByName(const char *name) { if(isCharLiteral(name)) return Token_sub_type_char_literal; if(isStringLiteral(name)) return Token_sub_type_str_literal; if(isOctNumber(name)) return Token_sub_type_dec_literal; if(isHexNumber(name)) return Token_sub_type_hex_literal; if(isOctNumber(name)) return Token_sub_type_oct_literal; if(isFloatNumber(name)) return Token_sub_type_float_literal; if(isDoubleNumber(name)) return Token_sub_type_double_literal; return Token_sub_type_err; }
Token_type getTokenTypeByName(const char *name) { if(isKeyword(name)) return Token_type_keyword; if(isCharLiteral(name)) return Token_type_literal; if(isStringLiteral(name)) return Token_type_literal; if(isVar(name)) return Token_type_var; if(isOperator(name)) return Token_type_operator; if(isDecNumber(name) || isHexNumber(name) || isOctNumber(name) || isFloatNumber(name) || isDoubleNumber(name)) return Token_type_num; if(isSemicolon(name)) return Token_type_semicolon; return Token_type_err; }