void QtSqlConnectionBackend::open(SqlDialect *dialect, const SqlSource &source) { close(); ScopedLock lock(drv_->conn_mux_); own_handle_ = true; conn_name_ = dialect->get_name() + _T("_") + source.db() + _T("_") + to_string(drv_->seq_); ++drv_->seq_; String driver = source.driver(); bool eat_slash = false; if (driver == _T("QTSQL")) { if (dialect->get_name() == _T("MYSQL")) driver = _T("QMYSQL"); else if (dialect->get_name() == _T("POSTGRES")) driver = _T("QPSQL"); else if (dialect->get_name() == _T("ORACLE")) driver = _T("QOCI"); else if (dialect->get_name() == _T("INTERBASE")) driver = _T("QIBASE"); else if (dialect->get_name() == _T("SQLITE")) driver = _T("QSQLITE"); if (dialect->native_driver_eats_slash() && !str_empty(source.db()) && char_code(source.db()[0]) == '/') eat_slash = true; } conn_ = new QSqlDatabase(QSqlDatabase::addDatabase(driver, conn_name_)); if (eat_slash) conn_->setDatabaseName(str_substr(source.db(), 1)); else conn_->setDatabaseName(source.db()); conn_->setUserName(source.user()); conn_->setPassword(source.passwd()); if (source.port() > 0) conn_->setPort(source.port()); if (!str_empty(source.host())) conn_->setHostName(source.host()); String options; Strings keys = source.options(); for (size_t i = 0; i < keys.size(); ++i) { if (!str_empty(options)) options += _T(";"); options += keys[i] + _T("=") + source[keys[i]]; } if (!str_empty(options)) conn_->setConnectOptions(options); if (!conn_->open()) throw DBError(conn_->lastError().text()); }
void char_count_for_seq(int charcnt[], /* output: char count */ int* n, /* output: str length of the sequence */ const char* buf, int r, /* row (begin from 0) of table in algorithm */ int m, /* step */ int g, /* shift */ int len) /* string length of the whole string in buf */ { int i; int index = 0; *n = 0; for (i = 0; (index = r + i * m) < len; ++i) { ++ charcnt [ (char_code(buf[index]) + g) % 26 ]; ++(*n); } }
void try_keys(int m) { int i, j; /* FILE* out = NULL; */ /* char filename[8] = { 0 }; */ for (i = 0; i < 26; ++i) { key[0] = 'a' + i; for (j = 1; j < m; ++j) { key[j] = code_char((char_code(key[0]) + key_equation[j]) % 26); } printf("=== key: %s\n", key); (void)vigenere_dec(key, m, buf, plaintext, BUF_LEN); /* sprintf(filename, "vig_out%02d", i); */ /* printf("%s\n", filename); */ printf("%s\n\n", plaintext); } }