Skip to content

Commit

Permalink
Quick cleanup and modernise code
Browse files Browse the repository at this point in the history
Update README.md
Update README.md
  • Loading branch information
bitsycore committed Oct 17, 2022
1 parent 7aa6e3d commit 7e48ac9
Show file tree
Hide file tree
Showing 14 changed files with 887 additions and 956 deletions.
37 changes: 16 additions & 21 deletions PassCoder/CLI.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
using System;
using System.Text.RegularExpressions;
namespace PassCoder;

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

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

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

GeneratePassword myGeneratePassword = new GeneratePassword(_myPhrase, _mySite);
myGeneratePassword.WriteFinal();
}
}
var myGeneratePassword = new GeneratePassword(myPhrase, mySite);
myGeneratePassword.WriteFinal();
}
}
18 changes: 6 additions & 12 deletions PassCoder/Constante.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System.Linq;
namespace PassCoder;

namespace PassCoder
public class Constant
{
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 };

public static ValuedSymboleList AllSymbole = new ValuedSymboleList("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");
public static ValuedSymboleList LetterSymbole = new ValuedSymboleList("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
public static ValuedSymboleList SpecialSymbole = new ValuedSymboleList(" !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");
public static ValuedSymboleList FigureSymbole = new ValuedSymboleList("0123456789");
}
public static ValuedSymbolList AllSymbol = new("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");
public static ValuedSymbolList LetterSymbol = new("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
public static ValuedSymbolList SpecialSymbol = new(" !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");
public static ValuedSymbolList FigureSymbol = new("0123456789");
}
161 changes: 77 additions & 84 deletions PassCoder/GeneratePassword.cs
Original file line number Diff line number Diff line change
@@ -1,97 +1,90 @@
using System;
namespace PassCoder;

using System;
using System.Text;

namespace PassCoder
public partial class Cli
{
public partial class CLI
{
public class GeneratePassword
{
private PhraseProcessed _phrase;
private PhraseProcessed _site;
private StringBuilder final = new StringBuilder("");

public GeneratePassword(PhraseProcessed phrase, PhraseProcessed site)
{
_phrase = phrase;
_site = site;
public class GeneratePassword
{
private readonly StringBuilder _final = new("");

uint offset_number = 0;
uint offset_letter = 0;
public GeneratePassword(PhraseProcessed phrase, PhraseProcessed site)
{
uint offsetNumber = 0;
uint offsetLetter = 0;

for (int i = 0; i < _site._base.Length; i++)
{
if (Char.IsLetter(site._base[i]))
{
offset_letter += _site._blendedSymboleList.Symbole2Value(site._base[i]) - _phrase._blendedSymboleList.Symbole2Value(site._base[i]);
}
else if (Char.IsNumber(site._base[i]))
{
offset_number += _site._blendedSymboleList.Symbole2Value(site._base[i]) - _phrase._blendedSymboleList.Symbole2Value(site._base[i]);
}
}
for (var i = 0; i < site.Base.Length; i++)
{
if (char.IsLetter(site.Base[i]))
{
offsetLetter += site.BlendedSymbolList.Symbol2Value(site.Base[i]) - phrase.BlendedSymbolList.Symbol2Value(site.Base[i]);
}
else if (char.IsNumber(site.Base[i]))
{
offsetNumber += site.BlendedSymbolList.Symbol2Value(site.Base[i]) - phrase.BlendedSymbolList.Symbol2Value(site.Base[i]);
}
}

for (int i = 0; i < phrase._base.Length; i++)
{
if (char.IsLetter(phrase._base[i]))
{
uint valueOffseted = Constant.LetterSymbole.Symbole2Value(phrase._base[i]);
valueOffseted += offset_letter;
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]))
{
uint to_int = (uint)Char.GetNumericValue(phrase._base[i]);
to_int += offset_number;
if (to_int >= Constant.FigureSymbole.Length())
to_int -= (uint)Constant.FigureSymbole.Length();
char charOffseted = Constant.FigureSymbole.Value2Symbole(to_int);
final.Append(charOffseted);
}
}
for (var i = 0; i < phrase.Base.Length; i++)
{
if (char.IsLetter(phrase.Base[i]))
{
var valueWithOffset = Constant.LetterSymbol.Symbol2Value(phrase.Base[i]);
valueWithOffset += offsetLetter;
if (valueWithOffset >= Constant.LetterSymbol.Length())
valueWithOffset -= Constant.LetterSymbol.Length();
var charWithOffset = Constant.LetterSymbol.Value2Symbol(valueWithOffset);
_final.Append(charWithOffset);
}
else if (char.IsNumber(phrase.Base[i]))
{
var toInt = (uint)char.GetNumericValue(phrase.Base[i]);
toInt += offsetNumber;
if (toInt >= Constant.FigureSymbol.Length())
toInt -= Constant.FigureSymbol.Length();
var charWithOffset = Constant.FigureSymbol.Value2Symbol(toInt);
_final.Append(charWithOffset);
}
}

//
uint newSeed = phrase._weightBlended + phrase._weightOriginal + site._weightBlended + site._weightOriginal;
RandGen newChaos = new RandGen(newSeed);
//
var newSeed = phrase.WeightBlended + phrase.WeightOriginal + site.WeightBlended + site.WeightOriginal;
var newChaos = new RandGen(newSeed);

ValuedSymboleList post_last = new ValuedSymboleList(final.ToString());
post_last.Randomize(newChaos);
final = new StringBuilder(post_last.List.ToString());
var postLast = new ValuedSymbolList(_final.ToString());
postLast.Randomize(newChaos);
_final = new StringBuilder(postLast.List.ToString());

// Check Size and compensate with adding symbole
UniqueSymbolePool poolSpecialSymbole = new UniqueSymbolePool(Constant.SpecialSymbole);
int number_special_to_add = 4;
if (final.Length <= 14)
{
number_special_to_add += (14 - final.Length);
}
// Check Size and compensate with adding symbol
var numberSpecialToAdd = 4;
if (_final.Length <= 14)
{
numberSpecialToAdd += 14 - _final.Length;
}

for (int i = 0; i < number_special_to_add; i++)
{
final.Append(Constant.SpecialSymbole.Value2Symbole(newChaos.Rand() % Constant.SpecialSymbole.Length()));
}
for (var i = 0; i < numberSpecialToAdd; i++)
{
_final.Append(Constant.SpecialSymbol.Value2Symbol(newChaos.Rand() % Constant.SpecialSymbol.Length()));
}

ValuedSymboleList last = new ValuedSymboleList(final.ToString());
last.Randomize(newChaos);
final = new StringBuilder(last.List.ToString());
}
var last = new ValuedSymbolList(_final.ToString());
last.Randomize(newChaos);
_final = new StringBuilder(last.List.ToString());
}

public void WriteFinal()
{
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();
}
}
}
public void WriteFinal()
{
Console.WriteLine("----------------------------");
Console.WriteLine("| Password Generated |");
Console.WriteLine("----------------------------");
Console.WriteLine();
Console.WriteLine(_final);
Console.WriteLine();
Console.WriteLine("----------------------------");
Console.WriteLine("| Press Any key to quit |");
Console.WriteLine("----------------------------");
Console.ReadLine();
}
}
}
2 changes: 1 addition & 1 deletion PassCoder/PassCoder.csproj.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>C:\Users\coldr\source\repos\PassCoder\PassCoder\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
<_LastSelectedProfileId>C:\Dev\pass-coder\PassCoder\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
Loading

0 comments on commit 7e48ac9

Please sign in to comment.