int main() { Waters09 waters; CharmList msk, pk, skBlinded, ct, transformOutputList; CharmListStr S; GT M, newM; ZR bf0; waters.setup(msk, pk); S.append("ONE"); S.append("TWO"); waters.keygen(pk, msk, S, bf0, skBlinded); M = waters.group.random(GT_t); string policy_str = "(ONE and TWO)"; waters.encrypt(pk, M, policy_str, ct); cout << "ct =\n" << ct << endl; int Y; waters.transform(pk, skBlinded, S, ct, transformOutputList, Y); cout << "transformCT =\n" << transformOutputList << endl; waters.decout(pk, S, transformOutputList, bf0, Y, newM); cout << convert_str(M) << endl; cout << convert_str(newM) << endl; if(M == newM) { cout << "Successful Decryption!" << endl; } else { cout << "FAILED Decryption." << endl; } return 0; }
Eigen::Matrix4f parse_registration(turtle_input& input, const std::string& guid_0, const std::string& guid_1) { std::pair<std::string, bool> t = parse_transformation_string(input, guid_0, guid_1); std::istringstream iss(t.first); std::vector<std::string> tokens{std::istream_iterator<std::string>{iss}, std::istream_iterator<std::string>{}}; assert(tokens.size() == 16); Eigen::Matrix4f m; for (uint32_t i = 0; i < 4; ++i) { for (uint32_t j = 0; j < 4; ++j) { double value; std::stringstream convert_str(tokens[i*4+j]); convert_str >> value; convert_str.str(""); m(i, j) = value; } } if (t.second) { Eigen::Matrix4f inv = m.inverse(); m = inv; } return m; }
void FileSystem::ListenForDirectoryChanges(std::string directory) { HANDLE h_Directory = ::CreateFile( directory.c_str(), // pointer to the file name FILE_LIST_DIRECTORY, // access (read/write) mode FILE_SHARE_READ // share mode | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, // security descriptor OPEN_EXISTING, // how to create FILE_FLAG_BACKUP_SEMANTICS // file attributes | FILE_FLAG_OVERLAPPED, NULL); // file with attributes to copy if (h_Directory == INVALID_HANDLE_VALUE) { std::cout << "ERROR: Error opening directory to watch: " << directory << std::endl; } int nCounter = 0; FILE_NOTIFY_INFORMATION strFileNotifyInfo[1024]; DWORD dwBytesReturned = 0; while(TRUE) { int count = 0; if( ReadDirectoryChangesW ( h_Directory, (LPVOID)&strFileNotifyInfo, sizeof(strFileNotifyInfo), TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE, &dwBytesReturned, NULL, NULL) == 0) { } else { wchar_t filename[MAX_PATH]; if (strFileNotifyInfo[0].FileNameLength) { wcsncpy_s(filename, MAX_PATH, strFileNotifyInfo[0].FileName, strFileNotifyInfo[0].FileNameLength / 2); filename[strFileNotifyInfo[0].FileNameLength / 2] = 0; std::wstring ws( filename ); std::string convert_str( ws.begin(), ws.end()); std::replace(convert_str.begin(), convert_str.end(), '\\', '/' ); for(std::vector<void (*)(std::string modified_file)>::iterator it = _change_listeners.begin(); it != _change_listeners.end(); ++it) { (*it)(directory + "/" + convert_str); } } } boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); } }
int utf8tostr(const char *src, char *dst, int dst_size, const char *enc) { char *old_locale = NULL; int ret; /* Get the name of the current locale. */ if (enc != NULL) old_locale = strdup(setlocale(LC_ALL, NULL)); else setlocale(LC_ALL, ""); ret = convert_str(enc != NULL ? enc : nl_langinfo(CODESET), LOCALE_UTF8, src, dst, dst_size); /* Restore the original locale. */ if (old_locale != NULL) { setlocale (LC_ALL, old_locale); free(old_locale); } return ret; }
static void draw_main(double x, double y, const char *string, struct rectangle *box) { #ifdef HAVE_FT2BUILD_H FT_Library library; FT_Face face; FT_Matrix matrix; /*FT_UInt glyph_index; */ FT_Vector pen; FT_Error ans; const char *filename; const char *encoding; int font_index; unsigned char *out; int outlen; /* get file name */ filename = font_get_freetype_name(); encoding = font_get_encoding(); font_index = font_get_index(); /* set freetype */ ans = FT_Init_FreeType(&library); if (ans) { /* DEBUG_LOG("Text3 error: ft init\n"); */ return; } ans = FT_New_Face(library, filename, font_index, &face); if (ans == FT_Err_Unknown_File_Format) { /* DEBUG_LOG("Text3 error: ft new face 1\n"); */ FT_Done_FreeType(library); return; } else if (ans) { /* DEBUG_LOG("Text3 error: ft new face 2\n"); */ FT_Done_FreeType(library); return; } /* ans = FT_Set_Pixel_Sizes(face,10,10); */ /* ans = FT_Set_Char_Size(face,text_size_x*64,text_size_y*64,0,0); */ /* ans = FT_Set_Char_Size(face,10*64,0,72,0); */ /* ans = FT_Set_Char_Size(face,text_size_x*64,text_size_y*64,72,72); */ ans = FT_Set_Char_Size(face, (int)(text_size_x * 64), (int)(text_size_y * 64), 100, 100); if (ans) { /* DEBUG_LOG("Text3 error: ft set size\n"); */ FT_Done_Face(face); FT_Done_FreeType(library); return; } /* init point */ pen.x = x * 64; /* pen.y = 0; */ pen.y = (screen_height - y) * 64; /* convert string to:shift-jis from:encoding */ outlen = convert_str(encoding, string, &out); /* set matrix */ set_matrix(&matrix); /* draw */ draw_text(face, &pen, &matrix, out, outlen, 0, box); /* release */ release_convert_str(out); /* FT_done */ FT_Done_Face(face); FT_Done_FreeType(library); #endif }
void benchmarkHVE(Hve08 & hve, ofstream & outfile1, ofstream & outfile2, int vectorSize, int iterationCount, CharmListStr & transformResults, CharmListStr & decoutResults) { Benchmark benchT, benchD; CharmList pk, msk, CT, skBlinded, transformOutputList; CharmMetaListG1 skComplete; CharmListInt S; int receivers[] = {1, 3, 5, 12, 14}; S.init(receivers, 5); GT M, newM; ZR uf1; int n = vectorSize; CharmListInt xVector, yVector; getRandomVector(yVector, vectorSize); xVector = yVector; // int _vectorX[] = {1, 1, 0, 1}; // int _vectorY[] = {1, 1, 0, 1}; // xVector.init(_vectorX, 4); // generate randomly // yVector.init(_vectorY, 4); hve.setup(n, pk, msk); // cout << "pk: " << pk << endl; // cout << "msk: " << msk << endl; hve.keygen(pk, msk, yVector, uf1, skBlinded); M = hve.group.random(GT_t); hve.encrypt(M, xVector, pk, CT); // cout << "ct :=\n" << CT << endl; double tf_in_ms, de_in_ms; stringstream s1, s2; for(int i = 0; i < iterationCount; i++) { benchT.start(); hve.transform(CT, skBlinded, transformOutputList); benchT.stop(); tf_in_ms = benchT.computeTimeInMilliseconds(); benchD.start(); hve.decout(transformOutputList, uf1, newM); benchD.stop(); de_in_ms = benchD.computeTimeInMilliseconds(); } cout << "Transform avg: " << benchT.getAverage() << " ms" << endl; s1 << vectorSize << " " << benchT.getAverage() << endl; outfile1 << s1.str(); transformResults[0] = benchT.getRawResultString(); cout << "Decout avg: " << benchD.getAverage() << " ms" << endl; s2 << vectorSize << " " << benchD.getAverage() << endl; outfile2 << s2.str(); decoutResults[0] = benchD.getRawResultString(); cout << convert_str(M) << endl; cout << convert_str(newM) << endl; if(M == newM) { cout << "Successful Decryption!" << endl; } else { cout << "FAILED Decryption." << endl; } }
int vzctl_convertstr(const char *src, char *dst, int dst_size) { setlocale(LC_ALL, ""); return convert_str(LOCALE_UTF8, nl_langinfo(CODESET), src, dst, dst_size); }