mirror of
https://github.com/wownero/wowlet.git
synced 2026-12-04 05:54:01 +01:00
Bootstrappable builds (WIP) [2]
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <monero_seed/monero_seed.hpp>
|
||||
#include "monero_seed/monero_seed.hpp"
|
||||
|
||||
#include "networktype.h"
|
||||
#include "utils/Utils.h"
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
|
||||
|
||||
#include "brute.h"
|
||||
|
||||
brute::brute(const std::string &chars) {
|
||||
this->chars = chars;
|
||||
this->len = chars.length();
|
||||
}
|
||||
|
||||
std::string brute::next() {
|
||||
std::string out;
|
||||
int c = count;
|
||||
int i;
|
||||
while (c >= 0){
|
||||
i = (c % len);
|
||||
out = chars[i] + out;
|
||||
c = (c / len) - 1;
|
||||
}
|
||||
count += 1;
|
||||
return out;
|
||||
}
|
||||
|
||||
bruteword::bruteword(const std::string &chars) {
|
||||
this->m_chars = chars;
|
||||
this->m_currentStrategy = strategy::ReplaceSingle;
|
||||
}
|
||||
|
||||
void bruteword::setWord(const std::string &word) {
|
||||
this->m_currentStrategy = strategy::ReplaceSingle;
|
||||
m_word = word;
|
||||
resetIndex();
|
||||
}
|
||||
|
||||
void bruteword::nextStrategy() {
|
||||
m_currentStrategy = static_cast<strategy>(static_cast<int>(m_currentStrategy) + 1);
|
||||
resetIndex();
|
||||
}
|
||||
|
||||
void bruteword::resetIndex() {
|
||||
iword = 0;
|
||||
ichar = 0;
|
||||
}
|
||||
|
||||
std::string bruteword::next() {
|
||||
std::string out = m_word;
|
||||
|
||||
switch(m_currentStrategy) {
|
||||
case strategy::ReplaceSingle: {
|
||||
if (iword >= m_word.length()) {
|
||||
this->nextStrategy();
|
||||
return next();
|
||||
}
|
||||
out[iword] = m_chars[ichar];
|
||||
ichar++;
|
||||
if (ichar == m_chars.length()){
|
||||
ichar = 0;
|
||||
iword++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
case strategy::AppendSingle: {
|
||||
if (ichar >= m_chars.length()) {
|
||||
this->nextStrategy();
|
||||
return next();
|
||||
}
|
||||
out += m_chars[ichar];
|
||||
ichar++;
|
||||
return out;
|
||||
}
|
||||
|
||||
case strategy::PrependSingle: {
|
||||
if (ichar >= m_chars.length()) {
|
||||
this->nextStrategy();
|
||||
return next();
|
||||
}
|
||||
out = m_chars[ichar] + out;
|
||||
ichar++;
|
||||
return out;
|
||||
}
|
||||
|
||||
case strategy::SwitchLetters: {
|
||||
if (iword+1 >= out.length()) {
|
||||
this->nextStrategy();
|
||||
return next();
|
||||
}
|
||||
char l = out[iword];
|
||||
out[iword] = out[iword+1];
|
||||
out[iword+1] = l;
|
||||
iword++;
|
||||
return out;
|
||||
}
|
||||
|
||||
case strategy::DeleteSingle: {
|
||||
if (iword >= out.length()) {
|
||||
this->nextStrategy();
|
||||
return next();
|
||||
}
|
||||
out = out.substr(0, iword) + out.substr(iword+1);
|
||||
iword++;
|
||||
return out;
|
||||
}
|
||||
|
||||
case strategy::AddSingle: {
|
||||
if (iword+1 >= out.length()) {
|
||||
this->nextStrategy();
|
||||
return next();
|
||||
}
|
||||
out = out.substr(0, iword+1) + m_chars[ichar] + out.substr(iword+1);
|
||||
ichar++;
|
||||
if (ichar == m_chars.length()) {
|
||||
ichar = 0;
|
||||
iword++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
case strategy::END: {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
|
||||
|
||||
#ifndef FEATHER_BRUTE_H
|
||||
#define FEATHER_BRUTE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class brute {
|
||||
public:
|
||||
explicit brute(const std::string &chars);
|
||||
|
||||
std::string next();
|
||||
|
||||
std::string chars;
|
||||
std::string current;
|
||||
int len;
|
||||
int count = 0;
|
||||
};
|
||||
|
||||
class bruteword {
|
||||
public:
|
||||
enum strategy {
|
||||
ReplaceSingle = 0,
|
||||
AppendSingle,
|
||||
PrependSingle,
|
||||
SwitchLetters,
|
||||
DeleteSingle,
|
||||
AddSingle,
|
||||
END
|
||||
};
|
||||
|
||||
explicit bruteword(const std::string &chars);
|
||||
void nextStrategy();
|
||||
void setWord(const std::string &word);
|
||||
|
||||
std::string next();
|
||||
|
||||
private:
|
||||
void resetIndex();
|
||||
|
||||
std::string m_chars;
|
||||
std::string m_word;
|
||||
strategy m_currentStrategy;
|
||||
|
||||
size_t iword = 0;
|
||||
size_t ichar = 0;
|
||||
};
|
||||
|
||||
#endif //FEATHER_BRUTE_H
|
||||
Reference in New Issue
Block a user