diff --git a/firmware/application/external/random_password/main.cpp b/firmware/application/external/random_password/main.cpp index 049eb25bf..4861914b0 100644 --- a/firmware/application/external/random_password/main.cpp +++ b/firmware/application/external/random_password/main.cpp @@ -38,7 +38,7 @@ __attribute__((section(".external_app.app_random_password.application_informatio /*.header_version = */ CURRENT_HEADER_VERSION, /*.app_version = */ VERSION_MD5, - /*.app_name = */ "random passwd", + /*.app_name = */ "Random passwd", /*.bitmap_data = */ { 0xC0, 0x03, diff --git a/firmware/application/external/random_password/ui_random_password.cpp b/firmware/application/external/random_password/ui_random_password.cpp index cbff01bd2..d293f83d4 100644 --- a/firmware/application/external/random_password/ui_random_password.cpp +++ b/firmware/application/external/random_password/ui_random_password.cpp @@ -1,8 +1,8 @@ /* * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2017 Furrtek - * copyleft zxkmm - * Copyright (C) 2024 HToToo + * Copyright (C) 2024 zxkmm + * Copyright (C) 2024 HTotoo * * This file is part of PortaPack. * @@ -86,7 +86,7 @@ RandomPasswordView::RandomPasswordView(NavigationView& nav) serial_format.bit_order = LSB_FIRST; persistent_memory::set_serial_format(serial_format); - progressbar.set_max(30); + progressbar.set_max(MAX_DIGITS * 2); check_log.set_value(logging); check_log.on_select = [this](Checkbox&, bool v) { @@ -151,16 +151,17 @@ RandomPasswordView::RandomPasswordView(NavigationView& nav) button_flood.on_select = [this](Button&) { if (flooding) { flooding = false; - button_flood.set_text("flood"); + button_flood.set_text(LanguageHelper::currentMessages[LANG_FLOOD]); } else { flooding = true; - button_flood.set_text("stop"); + button_flood.set_text(LanguageHelper::currentMessages[LANG_STOP]); } }; button_send.on_select = [this, &nav](Button&) { + async_prev_val = portapack::async_tx_enabled; portapack::async_tx_enabled = true; UsbSerialAsyncmsg::asyncmsg(password); - portapack::async_tx_enabled = false; + portapack::async_tx_enabled = async_prev_val; }; field_digits.on_change = [this](int32_t) { @@ -197,7 +198,7 @@ void RandomPasswordView::on_data(uint32_t value, bool is_data) { /// v feed deque seeds_deque.push_back(value); - if (seeds_deque.size() > MAX_DIGITS) { + if (seeds_deque.size() > MAX_DIGITS * 2) { seeds_deque.pop_front(); } @@ -205,7 +206,7 @@ void RandomPasswordView::on_data(uint32_t value, bool is_data) { progressbar.set_value(seeds_deque.size()); - if (flooding && seeds_deque.size() >= MAX_DIGITS) { + if (flooding && seeds_deque.size() >= MAX_DIGITS * 2) { new_password(); } @@ -217,7 +218,6 @@ void RandomPasswordView::on_data(uint32_t value, bool is_data) { void RandomPasswordView::clean_buffer() { seeds_deque = {}; - char_deque = {""}; } void RandomPasswordView::on_freqchg(int64_t freq) { @@ -234,7 +234,7 @@ void RandomPasswordView::set_random_freq() { } void RandomPasswordView::new_password() { - if (seeds_deque.size() < MAX_DIGITS) { + if (seeds_deque.size() < MAX_DIGITS * 2) { seeds_buffer_not_full = true; text_generated_passwd.set("wait seeds buffer full"); text_char_type_hints.set("then press generate"); @@ -274,12 +274,15 @@ void RandomPasswordView::new_password() { * (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 * 2; i += 2) { unsigned int seed = seeds_deque[i]; std::srand(seed); + uint8_t rollnum = (uint8_t)(seeds_deque[i + 1] % 128); + uint8_t nu = 0; + for (uint8_t o = 0; o < rollnum; ++o) nu = std::rand(); + nu++; char c = charset[std::rand() % charset.length()]; password += c; - char_deque.push_back(std::string(1, c)); if (std::isdigit(c)) { char_type_hints += "1"; @@ -304,19 +307,19 @@ void RandomPasswordView::new_password() { } if (check_auto_send.value() || flooding) { + async_prev_val = portapack::async_tx_enabled; portapack::async_tx_enabled = true; // printing out seeds buufer // for (auto seed : seeds_deque) { // UsbSerialAsyncmsg::asyncmsg(std::to_string(seed)); // } UsbSerialAsyncmsg::asyncmsg(password); - portapack::async_tx_enabled = false; + portapack::async_tx_enabled = async_prev_val; } clean_buffer(); } -// TODO: why flash and disappeared // tried: // 1. paint inline in new_password func // 2. paint in a seperate func and call from new_password @@ -328,7 +331,7 @@ void RandomPasswordView::paint_password_hints() { Painter painter; const int char_width = 8; const int char_height = 16; - const int start_y = 6 * char_height + 5; + const int start_y = 7 * char_height + 5; const int rect_height = 4; for (size_t i = 0; i < password.length(); i++) { diff --git a/firmware/application/external/random_password/ui_random_password.hpp b/firmware/application/external/random_password/ui_random_password.hpp index 4f22bfe34..c9ae20778 100644 --- a/firmware/application/external/random_password/ui_random_password.hpp +++ b/firmware/application/external/random_password/ui_random_password.hpp @@ -1,8 +1,8 @@ /* * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2017 Furrtek - * copyleft zxkmm - * Copyright (C) 2024 HToToo + * Copyright (C) 2024 zxkmm + * Copyright (C) 2024 HTotoo * * This file is part of PortaPack. * @@ -64,17 +64,17 @@ class RandomPasswordView : public View { void focus() override; - std::string title() const override { return "r.passwd"; }; + std::string title() const override { return "R.passwd"; }; private: unsigned int seed = 0; // extern void srand (unsigned int __seed) __THROW; std::string password = ""; std::deque seeds_deque = {0}; - std::deque char_deque = {""}; bool seeds_buffer_not_full = true; bool in_benchmark = false; bool flooding = false; bool logging = false; + bool async_prev_val = false; std::string str_log{""}; void on_data(uint32_t value, bool is_data); @@ -86,7 +86,7 @@ class RandomPasswordView : public View { NavigationView& nav_; RxRadioState radio_state_{}; app_settings::SettingsManager settings_{ - "rx_afsk", app_settings::Mode::RX}; + "rx_passgen", app_settings::Mode::RX}; Labels labels{ {{0 * 8, 0 * 16}, "------------seeds-------------", Theme::getInstance()->fg_light->foreground}, @@ -112,7 +112,7 @@ class RandomPasswordView : public View { Button button_modem_setup{ {screen_width - 12 * 8, 2 * 16 - 1, 96, 16 + 2}, - "AFSK modem"}; + LanguageHelper::currentMessages[LANG_MODEM_SETUP]}; Text text_seed{ {0, 2 * 16, 10 * 8, 16}, @@ -122,22 +122,22 @@ class RandomPasswordView : public View { {10 * 8 + 2, 2 * 16, screen_width - 96 - (10 * 8 + 4) - 1, 16}}; Text text_generated_passwd{ - {0, 4 * 16, screen_width, 28}, + {0, 4 * 16, screen_width, 16}, "000000000000000000000000000000"}; Text text_char_type_hints{ - {0, 5 * 16, screen_width, 28}, + {0, 5 * 16, screen_width, 16}, "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"}; Checkbox check_show_seeds{ {17 * 8, 8 * 16}, 6, - "show seed"}; + "Show seed"}; Checkbox check_auto_send{ {1 * 8, 8 * 16}, 20, - "auto send"}; + "Auto send"}; Checkbox check_punctuation{ {17 * 8, 12 * 16}, @@ -167,23 +167,23 @@ class RandomPasswordView : public View { Checkbox check_log{ {17 * 8, 10 * 16}, 3, - "savin"}; + LanguageHelper::currentMessages[LANG_SAVE]}; Button button_flood{ {0 * 8, 15 * 16 + 18, screen_width / 2, 22}, - "flood"}; + LanguageHelper::currentMessages[LANG_FLOOD]}; Button button_send{ {screen_width / 2 + 2, 15 * 16 + 18, screen_width / 2 - 2, 22}, - "send pwd"}; + "Send pwd"}; Button button_refresh{ {0 * 8, 17 * 16 + 10, screen_width / 2, 22}, - "generate"}; + "Generate"}; Button button_show_qr{ {screen_width / 2 + 2, 17 * 16 + 10, screen_width / 2 - 2, 22}, - "show QR"}; + LanguageHelper::currentMessages[LANG_SHOWQR]}; NumberField field_digits{ {16 * 8, 7 * 16 - 2}, diff --git a/firmware/common/ui_language.cpp b/firmware/common/ui_language.cpp index b961bf5a5..31c6bf945 100644 --- a/firmware/common/ui_language.cpp +++ b/firmware/common/ui_language.cpp @@ -1,7 +1,7 @@ #include "ui_language.hpp" // use the exact position in this array! the enum's value is the identifier. Best to add to the end -const char* LanguageHelper::englishMessages[] = {"OK", "Cancel", "Error", "Modem setup", "Debug", "Log", "Done", "Start", "Stop", "Scan", "Clear", "Ready", "Data:", "Loop", "Reset", "Pause", "Resume"}; +const char* LanguageHelper::englishMessages[] = {"OK", "Cancel", "Error", "Modem setup", "Debug", "Log", "Done", "Start", "Stop", "Scan", "Clear", "Ready", "Data:", "Loop", "Reset", "Pause", "Resume", "Flood", "Show QR", "Save"}; // multi language support will changes (not in use for now) const char** LanguageHelper::currentMessages = englishMessages; diff --git a/firmware/common/ui_language.hpp b/firmware/common/ui_language.hpp index 7d82a245c..1ae182218 100644 --- a/firmware/common/ui_language.hpp +++ b/firmware/common/ui_language.hpp @@ -55,7 +55,10 @@ enum LangConsts { LANG_LOOP, LANG_RESET, LANG_PAUSE, - LANG_RESUME + LANG_RESUME, + LANG_FLOOD, + LANG_SHOWQR, + LANG_SAVE }; class LanguageHelper {