Exemplo n.º 1
0
/**
*  Encrypts a string. Uses the hash function md5 in CFB (Cipher-feedback
*  mode).
*  @param message: arbitrary binary string to be encrypted.
*  @param key: arbitrary binary string to be used as a key.
*  @param [seed]: optional arbitrary binary string to be used as a seed.
*  if no seed is provided, the function uses the result of
*  <code>time()</code> as a seed.  
*  @return  The cyphertext (as a binary string).
*/
static int crypt (lua_State *L) {
  size_t lmsg;
  const char *msg = luaL_checklstring(L, 1, &lmsg);
  size_t lseed;
  const char *seed;
  int lblock;
  char block[BLOCKSIZE+MAXKEY];
  checkseed(L);
  seed = luaL_checklstring(L, 3, &lseed);
  if (lseed > BLOCKSIZE)
    luaL_error(L, "seed too long (> %d)", BLOCKSIZE);
  /* put seed and seed length at the beginning of result */
  block[0] = (char)lseed;
  memcpy(block+1, seed, lseed);
  lua_pushlstring(L, block, lseed+1);  /* to concat with result */
  lblock = initblock(L, seed, lseed, block);
  codestream(L, msg, lmsg, block, lblock);
  lua_concat(L, 2);
  return 1;
}
Exemplo n.º 2
0
	Function(std::string code){
		is_function = true;
		if (code.find("...") != std::string::npos){
			is_function = false;
			return;
		}

		while(code.find(" ") == 0){
			code.erase(0, 1);
		}

		std::stringstream codestream(code);
		std::getline(codestream, return_type, ' ');
		if (return_type.find("static") != std::string::npos){
			std::getline(codestream, return_type, ' ');
		}

		std::getline(codestream, name, '(');
		name = replace_all(name, " ", "");
		if (name.empty()){
			std::cout << code << std::endl;
		}

		if (has_substring(name, "*")){ // Our return type is actually a pointer
			name.erase(name.find("*"), 1); // Remove it from the name
			return_type += "*"; // And add it to the return type
		}
		if (name.empty()){
			std::getline(codestream, name, '(');
		}
		if (has_substring(name, "*")){ // * is from the function pointer, not the return type
			name.erase(name.find("*"), 1); // Just delete it and don't add it to the return type
		}
		name = replace_all(name, ")", "");

		// This somehow happens, and I don't understand.
		if (name.empty()){
			is_function = false;
			return;
		}

		std::string segment;
		while(std::getline(codestream, segment, ',')){
			if (segment.find("(") != std::string::npos){
				is_function = false;
				return;
			}

			// Cut off spaces in the beginning
			while(segment.find(" ") == 0){
				segment.erase(0, 1);
			}
			// Cut off after spaces
			if (has_substring(segment, "*")){
				segment.erase(segment.find("*") + 1, std::string::npos);
			}
			else if (has_substring(segment, "const") || has_substring(segment, "unsigned")){
				size_t cutoff = std::min(segment.find(" ", segment.find(" ") + 1), segment.find(")"));
				if (cutoff != std::string::npos){
					segment.erase(cutoff, std::string::npos); // Cut off after second space
				}
			}
			else if (has_substring(segment, " ")){
				segment.erase(segment.find(" "), std::string::npos);
			}
			replace_all(segment, ")", "");

			// Only the type is left -- TODO
			if (!segment.empty() && !has_substring(segment, "void") && segment.size() > 1){
				arguments.push_back(segment);
			}
		}
	}