Skip to content

Commit

Permalink
Cleaning and CLI simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsycore committed Oct 15, 2022
1 parent 280a27f commit 7aa6e3d
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 168 deletions.
26 changes: 26 additions & 0 deletions PassCoder/CLI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Text.RegularExpressions;

namespace PassCoder
{
public partial class CLI
{
private PhraseProcessed _myPhrase;
private PhraseProcessed _mySite;

public CLI(bool debug)
{
Console.WriteLine("----------------------------");
Console.WriteLine("| Enter Pass & Tag |");
Console.WriteLine("----------------------------");
Console.Write("PASS : ");
_myPhrase = new PhraseProcessed(Console.ReadLine(), debug);

Console.Write("TAG : ");
_mySite = new PhraseProcessed(Console.ReadLine(), debug);

GeneratePassword myGeneratePassword = new GeneratePassword(_myPhrase, _mySite);
myGeneratePassword.WriteFinal();
}
}
}
2 changes: 1 addition & 1 deletion PassCoder/Constante.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PassCoder
{
public class Constante
public class Constant
{
public int[] MajVariation = { 1, 3, 2, 1, 1, 4, 3, 1, 1, 4, 1, 2, 4, 1, 2, 4, 1, 2, 1, 1, 2, 1, 2, 3, 1, 2, 1, 1, 2, 3, 2 };
public int[] SymboleVariation = { 1, 4, 3, 2, 1, 2, 1, 2, 1, 1, 2, 1, 3, 2, 1, 1, 2, 1, 4, 1, 2, 1, 4, 1, 1, 2, 3, 1, 2, 1, 2, 1, 1, 2, 4, 1 };
Expand Down
70 changes: 24 additions & 46 deletions PassCoder/Core.cs → PassCoder/GeneratePassword.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
using System;
using System.Text;
using System.Text.RegularExpressions;

namespace PassCoder
{
public class Core
public partial class CLI
{
private PhraseProcessed _myPhrase;
private PhraseProcessed _mySite;

public Core()
{
Console.Write("Enter your Pass Phrase : ");
_myPhrase = new PhraseProcessed(Console.ReadLine());

Console.Write("Enter your Site Name : ");
_mySite = new PhraseProcessed(Console.ReadLine());

GeneratePassword myGeneratePassword = new GeneratePassword(_myPhrase, _mySite);
myGeneratePassword.WriteFinal();

Console.WriteLine("Press Anykey to quit");
Console.ReadLine();
}

public class GeneratePassword
{
private PhraseProcessed _phrase;
Expand Down Expand Up @@ -52,42 +33,36 @@ public GeneratePassword(PhraseProcessed phrase, PhraseProcessed site)

for (int i = 0; i < phrase._base.Length; i++)
{
if (Char.IsLetter(phrase._base[i]))
if (char.IsLetter(phrase._base[i]))
{
uint valueOffseted = Constante.LetterSymbole.Symbole2Value(phrase._base[i]);
uint valueOffseted = Constant.LetterSymbole.Symbole2Value(phrase._base[i]);
valueOffseted += offset_letter;
if (valueOffseted >= Constante.LetterSymbole.Length())
valueOffseted -= Constante.LetterSymbole.Length();
char charOffseted = Constante.LetterSymbole.Value2Symbole(valueOffseted);
if (valueOffseted >= Constant.LetterSymbole.Length())
valueOffseted -= Constant.LetterSymbole.Length();
char charOffseted = Constant.LetterSymbole.Value2Symbole(valueOffseted);
final.Append(charOffseted);
}
else if (Char.IsNumber(phrase._base[i]))
else if (char.IsNumber(phrase._base[i]))
{
uint to_int = (uint)Char.GetNumericValue(phrase._base[i]);
to_int += offset_number;
if (to_int >= Constante.FigureSymbole.Length())
to_int -= (uint) Constante.FigureSymbole.Length();
char charOffseted = Constante.FigureSymbole.Value2Symbole(to_int);
if (to_int >= Constant.FigureSymbole.Length())
to_int -= (uint)Constant.FigureSymbole.Length();
char charOffseted = Constant.FigureSymbole.Value2Symbole(to_int);
final.Append(charOffseted);
}
}

//uint newSeed = 0;
//for (int i = 0; i < ((phrase._lenght+site._lenght)%phrase._blendedSymboleList.List.Length); i++)
//{
// newSeed += (uint)(phrase._blendedSymboleList.List[i] + site._blendedSymboleList.List[i]);
//}

//
uint newSeed = phrase._weightBlended + phrase._weightOriginal + site._weightBlended + site._weightOriginal;

Chaos newChaos = new Chaos(newSeed);
RandGen newChaos = new RandGen(newSeed);

ValuedSymboleList post_last = new ValuedSymboleList(final.ToString());
post_last.Randomize(newChaos);
final = new StringBuilder(post_last.List.ToString());

// Check Size and compensate with adding symbole
UniqueSymbolePool poolSpecialSymbole = new UniqueSymbolePool(Constante.SpecialSymbole);
UniqueSymbolePool poolSpecialSymbole = new UniqueSymbolePool(Constant.SpecialSymbole);
int number_special_to_add = 4;
if (final.Length <= 14)
{
Expand All @@ -96,23 +71,26 @@ public GeneratePassword(PhraseProcessed phrase, PhraseProcessed site)

for (int i = 0; i < number_special_to_add; i++)
{
final.Append(Constante.SpecialSymbole.Value2Symbole(newChaos.Rand() % Constante.SpecialSymbole.Length()));
final.Append(Constant.SpecialSymbole.Value2Symbole(newChaos.Rand() % Constant.SpecialSymbole.Length()));
}

ValuedSymboleList last = new ValuedSymboleList(final.ToString());
last.Randomize(newChaos);
final = new StringBuilder(last.List.ToString());

// Count Upcase


}

public void WriteFinal()
{
Console.WriteLine("");
Console.WriteLine("------------------------");
Console.WriteLine("Final Password : " + final);
Console.WriteLine("----------------------------");
Console.WriteLine("| Password Generated |");
Console.WriteLine("----------------------------");
Console.WriteLine();
Console.WriteLine(final);
Console.WriteLine();
Console.WriteLine("----------------------------");
Console.WriteLine("| Press Anykey to quit |");
Console.WriteLine("----------------------------");
Console.ReadLine();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PassCoder/PassCoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<StartupObject>PassCoder.Program</StartupObject>
</PropertyGroup>

Expand Down
224 changes: 108 additions & 116 deletions PassCoder/PhraseProcessed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,121 +3,113 @@

namespace PassCoder
{
public class PhraseProcessed
{
public readonly string _name;
public readonly uint _lenght;
public readonly bool _even;

public readonly uint _weightOriginal;
public readonly uint _weightBlended;

public readonly uint _offset;

public readonly ValuedSymboleList _blendedSymboleList = new ValuedSymboleList(Constante.AllSymbole);

public StringBuilder _base = new StringBuilder();

public UniqueSymbolePool _poolLetter = new UniqueSymbolePool(Constante.LetterSymbole);
public UniqueSymbolePool _poolFigure = new UniqueSymbolePool(Constante.FigureSymbole);

public PhraseProcessed(string name)
{
Console.WriteLine();
Console.WriteLine("Information :");
Console.WriteLine("----------------------------------");
// Set Value
_name = name;
_lenght = (uint)name.Length;
Console.WriteLine("Length : " + _lenght);
_even = _lenght % 2 == 0;
Console.WriteLine("Even : " + (_even ? "true" : "false"));

// Generate SymboleBlend
// Seed create
var value = (uint)((_even ? 7 : 12) * _lenght);
for (var i = 0; i < _lenght; i++)
{
value += Constante.AllSymbole.Symbole2Value(_name[i]);
}
value *= Constante.AllSymbole.Length();

// Randomize create
Chaos chaos = new Chaos(value);

// Randomize
_blendedSymboleList.Randomize(chaos);

Console.WriteLine("Origi : " + Constante.AllSymbole.List);
Console.WriteLine("Randomize : " + _blendedSymboleList.List);

// Calculate WeightOriginal
_weightOriginal = 0;
for (int i = 0; i < _lenght; i++)
_weightOriginal += Constante.AllSymbole.Symbole2Value(name[i]);
_weightOriginal *= _lenght;
Console.WriteLine("WeightOriginal : " + _weightOriginal);

// Calculate WeightBlended
_weightBlended = 0;
for (int i = 0; i < _lenght; i++)
_weightBlended += _blendedSymboleList.Symbole2Value(name[i]);
_weightBlended *= _lenght;
Console.WriteLine("WeightBlended : " + _weightBlended);

// Calculate Offset
_offset = (_weightOriginal * _weightBlended - _lenght - _weightBlended) % Constante.AllSymbole.Length();
Console.WriteLine("Offset : " + _offset);

// Base String Calculate

ProcessBase();

Console.WriteLine("Base : " + _base);

//
Console.WriteLine();
}

private void ProcessBase()
{
string[] words = SplitWords();

for (int i = 0; i < words.Length; i++)
{
char to_add;
StringBuilder tempo = new StringBuilder("");
int size = words[i].Length;
if (char.IsLetter(words[i][0]))
{
uint valueOffseted = Constante.LetterSymbole.Symbole2Value(words[i][0]);
valueOffseted += _offset;
if (valueOffseted >= Constante.LetterSymbole.Length())
valueOffseted -= (uint) Constante.LetterSymbole.Length();
char charOffseted = Constante.LetterSymbole.Value2Symbole(valueOffseted);

to_add = _poolLetter.TryAdding(charOffseted);
if(to_add != '\0')
tempo.Append(to_add);
}
to_add = _poolFigure.TryAdding((words[i].Length%10).ToString()[0]);
if(to_add != '\0')
tempo.Append(to_add);
_base.Append(tempo);
}

}

private string[] SplitWords()
{
string[] words = _name.Split(' ');

for (int i = 0; i < words.Length; i++)
{
Console.WriteLine(i + " : " + words[i]);
public class PhraseProcessed
{
public string _name;
public uint _lenght;
public bool _even;
public uint _weightOriginal;
public uint _weightBlended;
public uint _offset;
public bool _debug;
public ValuedSymboleList _blendedSymboleList = new ValuedSymboleList(Constant.AllSymbole);
public StringBuilder _base = new StringBuilder();
public UniqueSymbolePool _poolLetter = new UniqueSymbolePool(Constant.LetterSymbole);
public UniqueSymbolePool _poolFigure = new UniqueSymbolePool(Constant.FigureSymbole);

public PhraseProcessed(string name, bool debug)
{
// Set Value
_name = name;
_lenght = (uint)name.Length;
_even = _lenght % 2 == 0;
_debug = debug;

// Generate SymboleBlend
// Seed create
var value = (uint)((_even ? 7 : 12) * _lenght);
for (var i = 0; i < _lenght; i++)
{
value += Constant.AllSymbole.Symbole2Value(_name[i]);
}
value *= Constant.AllSymbole.Length();

// Randomize create
RandGen chaos = new RandGen(value);

// Randomize
_blendedSymboleList.Randomize(chaos);


// Calculate WeightOriginal
_weightOriginal = 0;
for (int i = 0; i < _lenght; i++)
_weightOriginal += Constant.AllSymbole.Symbole2Value(name[i]);
_weightOriginal *= _lenght;


// Calculate WeightBlended
_weightBlended = 0;
for (int i = 0; i < _lenght; i++)
_weightBlended += _blendedSymboleList.Symbole2Value(name[i]);
_weightBlended *= _lenght;


// Calculate Offset
_offset = (_weightOriginal * _weightBlended - _lenght - _weightBlended) % Constant.AllSymbole.Length();

string[] words = _name.Split(' ');

// Base String Calculate
ProcessBase(words);

if (_debug)
{
Console.WriteLine("----------------------------");
Console.WriteLine("| Debug |");
Console.WriteLine("----------------------------");
Console.WriteLine("Length : " + _lenght);
Console.WriteLine("Even : " + (_even ? "true" : "false"));
Console.WriteLine("Origi : " + Constant.AllSymbole.List);
Console.WriteLine("Rand : " + _blendedSymboleList.List);
Console.WriteLine("WeightO : " + _weightOriginal);
Console.WriteLine("WeightB : " + _weightBlended);
Console.WriteLine("Offset : " + _offset);
Console.WriteLine("Base : " + _base);
Console.WriteLine("Words : " + _base);
for (int i = 0; i < words.Length; i++)
{
Console.Write("[" + i + "] " + words[i]);
Console.WriteLine();
}
}
}

private void ProcessBase(string[] words)
{
for (int i = 0; i < words.Length; i++)
{
char to_add;
StringBuilder tempo = new StringBuilder("");
int size = words[i].Length;
if (char.IsLetter(words[i][0]))
{
uint valueOffseted = Constant.LetterSymbole.Symbole2Value(words[i][0]);
valueOffseted += _offset;
if (valueOffseted >= Constant.LetterSymbole.Length())
valueOffseted -= (uint)Constant.LetterSymbole.Length();
char charOffseted = Constant.LetterSymbole.Value2Symbole(valueOffseted);

to_add = _poolLetter.TryAdding(charOffseted);
if (to_add != '\0')
tempo.Append(to_add);
}
to_add = _poolFigure.TryAdding((words[i].Length % 10).ToString()[0]);
if (to_add != '\0')
tempo.Append(to_add);
_base.Append(tempo);
}
}
}
}

return words;
}
}
}
Loading

0 comments on commit 7aa6e3d

Please sign in to comment.