Compare commits

...

3 Commits

Author SHA1 Message Date
zxkmm
7f6829f224
Merge 193545b6da into b43eaa8786 2024-09-29 17:06:45 +00:00
zxkmm
193545b6da user another methods to generate 2024-09-30 01:06:30 +08:00
zxkmm
14ef1332aa init in methods local var 2024-09-29 21:28:36 +08:00
2 changed files with 50 additions and 10 deletions

View File

@ -2,6 +2,7 @@
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek * Copyright (C) 2017 Furrtek
* copyleft zxkmm * copyleft zxkmm
* Copyright (C) 2024 HToToo
* *
* This file is part of PortaPack. * This file is part of PortaPack.
* *
@ -72,7 +73,8 @@ RandomPasswordView::RandomPasswordView(NavigationView& nav)
&button_send, &button_send,
&field_digits, &field_digits,
&check_allow_confusable_chars, &check_allow_confusable_chars,
&text_seed}); &text_seed,
&progressbar});
// no idea what's these, i copied from afsk rx app and they seems needed' // no idea what's these, i copied from afsk rx app and they seems needed'
auto def_bell202 = &modem_defs[0]; auto def_bell202 = &modem_defs[0];
@ -84,6 +86,8 @@ RandomPasswordView::RandomPasswordView(NavigationView& nav)
serial_format.bit_order = LSB_FIRST; serial_format.bit_order = LSB_FIRST;
persistent_memory::set_serial_format(serial_format); persistent_memory::set_serial_format(serial_format);
progressbar.set_max(30);
check_log.set_value(logging); check_log.set_value(logging);
check_log.on_select = [this](Checkbox&, bool v) { check_log.on_select = [this](Checkbox&, bool v) {
if (v) { if (v) {
@ -160,6 +164,7 @@ RandomPasswordView::RandomPasswordView(NavigationView& nav)
}; };
field_digits.on_change = [this](int32_t) { field_digits.on_change = [this](int32_t) {
clean_buffer();
this->new_password(); this->new_password();
}; };
@ -191,12 +196,27 @@ void RandomPasswordView::on_data(uint32_t value, bool is_data) {
if (is_data) { if (is_data) {
seed = static_cast<unsigned int>(value); seed = static_cast<unsigned int>(value);
text_seed.set(to_string_dec_uint(check_show_seeds.value() ? seed : 0)); text_seed.set(to_string_dec_uint(check_show_seeds.value() ? seed : 0));
/// v feed deque
seeds_deque.push_back(value);
if (seeds_deque.size() > MAX_DIGITS) {
seeds_deque.pop_front();
}
///^ feed deque
progressbar.set_value(seeds_deque.size());
} else { } else {
text_generated_passwd.set("Baudrate estimation: ~"); text_generated_passwd.set("Baudrate estimation: ~");
text_char_type_hints.set(to_string_dec_uint(value)); text_char_type_hints.set(to_string_dec_uint(value));
} }
} }
void RandomPasswordView::clean_buffer() {
seeds_deque = {0};
char_deque = {""};
}
void RandomPasswordView::on_freqchg(int64_t freq) { void RandomPasswordView::on_freqchg(int64_t freq) {
field_frequency.set_value(freq); field_frequency.set_value(freq);
} }
@ -212,8 +232,8 @@ void RandomPasswordView::set_random_freq() {
void RandomPasswordView::new_password() { void RandomPasswordView::new_password() {
password = ""; password = "";
std::string charset; std::string charset = "";
std::string char_type_hints; std::string char_type_hints = "";
if (check_digits.value()) if (check_digits.value())
charset += "0123456789"; charset += "0123456789";
@ -233,22 +253,31 @@ void RandomPasswordView::new_password() {
if (charset.empty()) { if (charset.empty()) {
text_generated_passwd.set("generate failed,"); text_generated_passwd.set("generate failed,");
text_char_type_hints.set("select at least 1 type"); text_char_type_hints.set("select at least 1 type");
return; return;
} }
if (seed == 0) { if (seeds_deque.size() < MAX_DIGITS) {
text_generated_passwd.set("generate failed,"); seeds_buffer_not_full = true;
text_char_type_hints.set("random seed exception"); text_generated_passwd.set("wait seeds buffer full");
} else { text_char_type_hints.set("then press generate");
std::srand(seed); // extern void srand (unsigned int __seed) __THROW; return;
} }
int password_length = field_digits.value(); int password_length = field_digits.value();
/*the seeds_buffer were feed streaming by AFSK,
* and when generate, it use each seed for each char, and uint seeds totally can generate UINT_MAX result,
* which already cover the 10+26+25+4 (123+abc+abc+.!)
* so total possible password would be PW_LENGTH ^ (10+26+25+4), which already covered all the possible solution
* (assume AFSK data is averaged in chaotic space, which maybe no one can garentee but I hope so)
* */
for (int i = 0; i < password_length; i++) { for (int i = 0; i < password_length; i++) {
unsigned int seed = seeds_deque[i];
std::srand(seed);
char c = charset[std::rand() % charset.length()]; char c = charset[std::rand() % charset.length()];
password += c; password += c;
char_deque.push_back(std::string(1, c));
if (std::isdigit(c)) { if (std::isdigit(c)) {
char_type_hints += "1"; char_type_hints += "1";

View File

@ -2,6 +2,7 @@
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek * Copyright (C) 2017 Furrtek
* copyleft zxkmm * copyleft zxkmm
* Copyright (C) 2024 HToToo
* *
* This file is part of PortaPack. * This file is part of PortaPack.
* *
@ -24,6 +25,8 @@
#ifndef __UI_RANDOM_PASSWORD_H__ #ifndef __UI_RANDOM_PASSWORD_H__
#define __UI_RANDOM_PASSWORD_H__ #define __UI_RANDOM_PASSWORD_H__
#define MAX_DIGITS 30
#include "ui.hpp" #include "ui.hpp"
#include "ui_language.hpp" #include "ui_language.hpp"
#include "ui_navigation.hpp" #include "ui_navigation.hpp"
@ -36,12 +39,13 @@
#include "utility.hpp" #include "utility.hpp"
#include "ui_qrcode.hpp" #include "ui_qrcode.hpp"
#include "usb_serial_asyncmsg.hpp" #include "usb_serial_asyncmsg.hpp"
#include <deque>
using namespace ui; using namespace ui;
namespace ui::external_app::random_password { namespace ui::external_app::random_password {
class RandomPasswordLogger { class RandomPasswordLogger { // TODO: log is broken after introduced the buffer thing
public: public:
Optional<File::Error> append(const std::filesystem::path& filename) { Optional<File::Error> append(const std::filesystem::path& filename) {
return log_file.append(filename); return log_file.append(filename);
@ -65,8 +69,12 @@ class RandomPasswordView : public View {
private: private:
unsigned int seed = 0; // extern void srand (unsigned int __seed) __THROW; unsigned int seed = 0; // extern void srand (unsigned int __seed) __THROW;
std::string password = ""; std::string password = "";
std::deque<unsigned int> seeds_deque = {0};
std::deque<std::string> char_deque = {""};
bool seeds_buffer_not_full = true;
void on_data(uint32_t value, bool is_data); void on_data(uint32_t value, bool is_data);
void clean_buffer();
void new_password(); void new_password();
std::string generate_log_line(); std::string generate_log_line();
void paint_password_hints(); void paint_password_hints();
@ -110,6 +118,9 @@ class RandomPasswordView : public View {
{0, 2 * 16, screen_width / 2, 16}, {0, 2 * 16, screen_width / 2, 16},
"0000000000"}; "0000000000"};
ProgressBar progressbar{
{screen_width / 2 + 1, 2 * 16, screen_width - 96 - (0 * 8 + screen_width / 2 + 1) - 1, 16}};
Text text_generated_passwd{ Text text_generated_passwd{
{0, 4 * 16, screen_width, 28}, {0, 4 * 16, screen_width, 28},
"000000000000000000000000000000"}; "000000000000000000000000000000"};