pax_global_header 0000666 0000000 0000000 00000000064 14736317116 0014523 g ustar 00root root 0000000 0000000 52 comment=4064e658131c61840a18310e69ddc5f7ffd392fd
HIBPOfflineCheck-1.7.11/ 0000775 0000000 0000000 00000000000 14736317116 0014575 5 ustar 00root root 0000000 0000000 HIBPOfflineCheck-1.7.11/.gitignore 0000664 0000000 0000000 00000000244 14736317116 0016565 0 ustar 00root root 0000000 0000000 .vs
HIBPOfflineCheck/bin/*
HIBPOfflineCheck/obj/*
screen.png
HIBPOfflineCheck/plgx/*
*.plgx
release_checklist.txt
HIBPOfflineCheck.plgx.asc
*temp.bat
*.csproj.user
HIBPOfflineCheck-1.7.11/HIBPOfflineCheck.sln 0000664 0000000 0000000 00000002615 14736317116 0020302 0 ustar 00root root 0000000 0000000
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HIBPOfflineCheck", "HIBPOfflineCheck\HIBPOfflineCheck.csproj", "{B4DFC614-CDC6-43BE-8D6A-D4EFD47BB79E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CBAC84C5-9B4A-49AC-AF7A-942AF54371BE}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
readme.md = readme.md
version.txt = version.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B4DFC614-CDC6-43BE-8D6A-D4EFD47BB79E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4DFC614-CDC6-43BE-8D6A-D4EFD47BB79E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4DFC614-CDC6-43BE-8D6A-D4EFD47BB79E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4DFC614-CDC6-43BE-8D6A-D4EFD47BB79E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C293D69A-1DFC-4B64-9DD3-0D29FBA18769}
EndGlobalSection
EndGlobal
HIBPOfflineCheck-1.7.11/HIBPOfflineCheck/ 0000775 0000000 0000000 00000000000 14736317116 0017560 5 ustar 00root root 0000000 0000000 HIBPOfflineCheck-1.7.11/HIBPOfflineCheck/BitStorage.cs 0000664 0000000 0000000 00000004740 14736317116 0022157 0 ustar 00root root 0000000 0000000 using System.Collections;
using System.IO;
namespace HIBPOfflineCheck
{
class BitStorage
{
private BitArray[] master;
private const int subArraySize = 64 * 1024 * 1024;
public ulong Length { get; private set; }
public BitStorage(ulong length) : this(length, true) { }
public BitStorage(ulong length, bool allocateMem)
{
Length = length;
int remainder = (int)(length % subArraySize);
int numberSubArrays;
int lastArraySize;
if (remainder == 0)
{
numberSubArrays = (int)(length / subArraySize);
master = new BitArray[numberSubArrays];
if (allocateMem)
{
for (int i = 0; i < master.Length; ++i)
master[i] = new BitArray(subArraySize);
}
}
else
{
numberSubArrays = (int)(length / subArraySize) + 1;
//lastArraySize = remainder;
lastArraySize = subArraySize;
master = new BitArray[numberSubArrays];
if (allocateMem)
{
for (int i = 0; i < master.Length - 1; ++i)
master[i] = new BitArray(subArraySize);
master[master.Length - 1] = new BitArray(lastArraySize);
}
}
}
public bool GetValue(ulong index)
{
ulong row = index / subArraySize;
int col = (int) (index % subArraySize);
return master[row][col];
}
public void SetValue(ulong index, bool value)
{
ulong row = index / subArraySize;
int col = (int) (index % subArraySize);
master[row][col] = value;
}
public void Save(BinaryWriter binaryWriter)
{
for (int i = 0; i < master.Length; i++)
{
byte[] bytes = new byte[subArraySize / 8];
master[i].CopyTo(bytes, 0);
binaryWriter.Write(bytes);
}
}
public void Load(BinaryReader binaryReader)
{
int chunkSize = subArraySize / 8;
byte[] bytes = new byte[chunkSize];
for (int i = 0; i < master.Length; i++)
{
binaryReader.Read(bytes, 0, chunkSize);
master[i] = new BitArray(bytes);
}
}
}
}
HIBPOfflineCheck-1.7.11/HIBPOfflineCheck/BloomFilter.cs 0000664 0000000 0000000 00000023012 14736317116 0022323 0 ustar 00root root 0000000 0000000 using System;
using System.IO;
namespace HIBPOfflineCheck
{
public class BloomFilter
{
private BitStorage hashBits;
public long Capacity { get; private set; }
public float ErrorRate { get; private set; }
public ulong BitCount { get; private set; }
public uint NumHashFuncs { get; private set; }
public int Algorithm { get; private set; }
public BloomFilter(long capacity, float errorRate)
: this(capacity, errorRate, bestM(capacity, errorRate), bestK(capacity, errorRate)) { }
public BloomFilter(long capacity, float errorRate, ulong bitCount, uint numHashFuncs)
{
if (capacity <= 0)
throw new ArgumentOutOfRangeException("capacity", capacity, "capacity must be positive");
if (errorRate >= 1 || errorRate <= 0)
throw new ArgumentOutOfRangeException("errorRate", errorRate, "errorRate must be between 0 and 1");
Capacity = capacity;
ErrorRate = errorRate;
BitCount = bitCount;
NumHashFuncs = numHashFuncs;
// different algorithms could be added in the future
Algorithm = 0;
hashBits = new BitStorage(bitCount);
}
public BloomFilter(string filename)
{
Load(filename);
}
public void Save(string filename)
{
using (Stream stream = new FileStream(filename, FileMode.Create))
using (BinaryWriter bw = new BinaryWriter(stream))
{
bw.Write(Capacity);
bw.Write(ErrorRate);
bw.Write(BitCount);
bw.Write(NumHashFuncs);
bw.Write(Algorithm);
hashBits.Save(bw);
}
}
public void Load(string filename)
{
if (!File.Exists(filename))
{
throw new FileNotFoundException();
}
using (Stream stream = new FileStream(filename, FileMode.Open))
using (BinaryReader br = new BinaryReader(stream))
{
Capacity = br.ReadInt64();
ErrorRate = br.ReadSingle();
BitCount = (ulong)br.ReadInt64();
NumHashFuncs = (uint) br.ReadInt32();
Algorithm = br.ReadInt32();
hashBits = new BitStorage(BitCount, false);
hashBits.Load(br);
}
}
public void Add(string item)
{
for (uint i = 0; i < NumHashFuncs / 2; i++)
{
byte[] bitem = HexToByte(item);
ulong[] hash = ComputeHash(bitem, i);
hashBits.SetValue(hash[0] % hashBits.Length, true);
hashBits.SetValue(hash[1] % hashBits.Length, true);
}
}
public bool Contains(string item)
{
for (uint i = 0; i < NumHashFuncs / 2; i++)
{
byte[] bitem = HexToByte(item);
ulong[] hash = ComputeHash(bitem, i);
if (hashBits.GetValue(hash[0] % hashBits.Length) == false)
return false;
if (hashBits.GetValue(hash[1] % hashBits.Length) == false)
return false;
}
return true;
}
private static uint bestK(long capacity, float errorRate)
{
return (uint)Math.Round(Math.Log(2.0) * bestM(capacity, errorRate) / capacity);
}
private static ulong bestM(long capacity, float errorRate)
{
return (ulong)Math.Ceiling(capacity * Math.Log(errorRate, (1.0 / Math.Pow(2, Math.Log(2.0)))));
}
// Hex string to byte array - efficient conversion
// https://stackoverflow.com/a/6274772
public static byte[] HexToByte(string input)
{
var outputLength = input.Length / 2;
var output = new byte[outputLength];
int k = 0;
for (int i = 0; i < input.Length; i += 2)
{
byte b = (byte)(LookupTable[input[i]] << 4 | LookupTable[input[i + 1]]);
output[k++] = b;
}
return output;
}
private static readonly byte[] LookupTable = new byte[] {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
// Murmur3 implementation
// http://blog.teamleadnet.com/2012/08/murmurhash3-ultra-fast-hash-algorithm.html
public ulong[] ComputeHash(byte[] bb, uint seed)
{
ulong READ_SIZE = 16;
ulong length = 0L;
ulong h1 = 0L;
ulong h2 = 0L;
h1 = seed;
int pos = 0;
ulong remaining = (ulong)bb.Length;
// read 128 bits, 16 bytes, 2 longs in eacy cycle
while (remaining >= READ_SIZE)
{
ulong k1 = GetUInt64(bb, pos);
pos += 8;
ulong k2 = GetUInt64(bb, pos);
pos += 8;
length += READ_SIZE;
remaining -= READ_SIZE;
h1 ^= MixKey1(k1);
h1 = RotateLeft(h1, 27);
h1 += h2;
h1 = h1 * 5 + 0x52dce729;
h2 ^= MixKey2(k2);
h2 = RotateLeft(h2, 31);
h2 += h1;
h2 = h2 * 5 + 0x38495ab5;
}
// if the input contains more than 16 bytes
if (remaining > 0)
{
ulong k1 = 0;
ulong k2 = 0;
length += remaining;
// little endian (x86) processing
switch (remaining)
{
case 15:
k2 ^= (ulong)bb[pos + 14] << 48;
goto case 14;
case 14:
k2 ^= (ulong)bb[pos + 13] << 40;
goto case 13;
case 13:
k2 ^= (ulong)bb[pos + 12] << 32;
goto case 12;
case 12:
k2 ^= (ulong)bb[pos + 11] << 24;
goto case 11;
case 11:
k2 ^= (ulong)bb[pos + 10] << 16;
goto case 10;
case 10:
k2 ^= (ulong)bb[pos + 9] << 8;
goto case 9;
case 9:
k2 ^= (ulong)bb[pos + 8];
goto case 8;
case 8:
k1 ^= GetUInt64(bb, pos);
break;
case 7:
k1 ^= (ulong)bb[pos + 6] << 48;
goto case 6;
case 6:
k1 ^= (ulong)bb[pos + 5] << 40;
goto case 5;
case 5:
k1 ^= (ulong)bb[pos + 4] << 32;
goto case 4;
case 4:
k1 ^= (ulong)bb[pos + 3] << 24;
goto case 3;
case 3:
k1 ^= (ulong)bb[pos + 2] << 16;
goto case 2;
case 2:
k1 ^= (ulong)bb[pos + 1] << 8;
goto case 1;
case 1:
k1 ^= (ulong)bb[pos];
break;
default:
throw new Exception("Something went wrong with remaining bytes calculation.");
}
h1 ^= MixKey1(k1);
h2 ^= MixKey2(k2);
}
h1 ^= length;
h2 ^= length;
h1 += h2;
h2 += h1;
h1 = MixFinal(h1);
h2 = MixFinal(h2);
h1 += h2;
h2 += h1;
return new[] { h1, h2 };
}
private static ulong MixKey1(ulong k1)
{
k1 *= 0x87c37b91114253d5L;
k1 = RotateLeft(k1, 31);
k1 *= 0x4cf5ad432745937fL;
return k1;
}
private static ulong MixKey2(ulong k2)
{
k2 *= 0x4cf5ad432745937fL;
k2 = RotateLeft(k2, 33);
k2 *= 0x87c37b91114253d5L;
return k2;
}
private static ulong MixFinal(ulong k)
{
// avalanche bits
k ^= k >> 33;
k *= 0xff51afd7ed558ccdL;
k ^= k >> 33;
k *= 0xc4ceb9fe1a85ec53L;
k ^= k >> 33;
return k;
}
public static ulong RotateLeft(ulong original, int bits)
{
return (original << bits) | (original >> (64 - bits));
}
private static ulong GetUInt64(byte[] bb, int pos)
{
return BitConverter.ToUInt64(bb, pos);
}
}
} HIBPOfflineCheck-1.7.11/HIBPOfflineCheck/CreateBloomFilter.Designer.cs 0000664 0000000 0000000 00000022307 14736317116 0025214 0 ustar 00root root 0000000 0000000 namespace HIBPOfflineCheck
{
partial class CreateBloomFilter
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.textBoxOutput = new System.Windows.Forms.TextBox();
this.buttonSelectOutput = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.progressBar = new System.Windows.Forms.ProgressBar();
this.buttonSelectInput = new System.Windows.Forms.Button();
this.textBoxInput = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.labelInfo = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// textBoxOutput
//
this.textBoxOutput.Location = new System.Drawing.Point(9, 32);
this.textBoxOutput.Name = "textBoxOutput";
this.textBoxOutput.Size = new System.Drawing.Size(360, 20);
this.textBoxOutput.TabIndex = 1;
//
// buttonSelectOutput
//
this.buttonSelectOutput.Location = new System.Drawing.Point(373, 30);
this.buttonSelectOutput.Name = "buttonSelectOutput";
this.buttonSelectOutput.Size = new System.Drawing.Size(70, 23);
this.buttonSelectOutput.TabIndex = 2;
this.buttonSelectOutput.Text = "Browse...";
this.buttonSelectOutput.UseVisualStyleBackColor = true;
this.buttonSelectOutput.Click += new System.EventHandler(this.buttonSelectOutput_Click);
//
// buttonCreate
//
this.buttonCreate.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.buttonCreate.Location = new System.Drawing.Point(152, 211);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 3;
this.buttonCreate.Text = "Generate";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// progressBar
//
this.progressBar.Location = new System.Drawing.Point(12, 182);
this.progressBar.Name = "progressBar";
this.progressBar.Size = new System.Drawing.Size(449, 23);
this.progressBar.TabIndex = 4;
this.progressBar.Visible = false;
//
// buttonSelectInput
//
this.buttonSelectInput.Location = new System.Drawing.Point(373, 30);
this.buttonSelectInput.Name = "buttonSelectInput";
this.buttonSelectInput.Size = new System.Drawing.Size(70, 23);
this.buttonSelectInput.TabIndex = 5;
this.buttonSelectInput.Text = "Browse...";
this.buttonSelectInput.UseVisualStyleBackColor = true;
this.buttonSelectInput.Click += new System.EventHandler(this.buttonSelectInput_Click);
//
// textBoxInput
//
this.textBoxInput.Location = new System.Drawing.Point(9, 32);
this.textBoxInput.Name = "textBoxInput";
this.textBoxInput.Size = new System.Drawing.Size(360, 20);
this.textBoxInput.TabIndex = 6;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(101, 13);
this.label2.TabIndex = 7;
this.label2.Text = "HIBP passwords file";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 16);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(58, 13);
this.label3.TabIndex = 8;
this.label3.Text = "Bloom filter";
//
// labelInfo
//
this.labelInfo.AutoSize = true;
this.labelInfo.Location = new System.Drawing.Point(9, 166);
this.labelInfo.Name = "labelInfo";
this.labelInfo.Size = new System.Drawing.Size(279, 13);
this.labelInfo.TabIndex = 9;
this.labelInfo.Text = "Generating the filter may take several minutes to complete, depending on your hardware.";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.textBoxInput);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.buttonSelectInput);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(449, 68);
this.groupBox1.TabIndex = 10;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Input";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.buttonSelectOutput);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.textBoxOutput);
this.groupBox2.Location = new System.Drawing.Point(12, 86);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(449, 67);
this.groupBox2.TabIndex = 11;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Output";
//
// buttonCancel
//
this.buttonCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.buttonCancel.Location = new System.Drawing.Point(233, 211);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 12;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// CreateBloomFilter
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(473, 246);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.labelInfo);
this.Controls.Add(this.progressBar);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "CreateBloomFilter";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Create Bloom Filter";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.CreateBloomFilter_FormClosed);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBoxOutput;
private System.Windows.Forms.Button buttonSelectOutput;
private System.Windows.Forms.Button buttonCreate;
private System.Windows.Forms.ProgressBar progressBar;
private System.Windows.Forms.Button buttonSelectInput;
private System.Windows.Forms.TextBox textBoxInput;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label labelInfo;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button buttonCancel;
}
} HIBPOfflineCheck-1.7.11/HIBPOfflineCheck/CreateBloomFilter.cs 0000664 0000000 0000000 00000012716 14736317116 0023460 0 ustar 00root root 0000000 0000000 using KeePass.App;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HIBPOfflineCheck
{
public partial class CreateBloomFilter : Form
{
private HIBPOfflineCheckExt ext;
private CancellationTokenSource cancellationTokenSource;
private Stopwatch stopwatch;
private System.Windows.Forms.Timer timer;
public CreateBloomFilter(HIBPOfflineCheckExt ext)
{
InitializeComponent();
this.ext = ext;
textBoxInput.Text = ext.Prov.PluginOptions.HIBPFileName;
Icon = AppIcons.Default;
cancellationTokenSource = new CancellationTokenSource();
stopwatch = new Stopwatch();
timer = new System.Windows.Forms.Timer();
timer.Tick += TimerTick;
timer.Interval = 1000;
}
private void buttonSelectInput_Click(object sender, EventArgs e)
{
var openDialog = new OpenFileDialog();
openDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
if (openDialog.ShowDialog() == DialogResult.OK)
{
string file = openDialog.FileName;
textBoxInput.Text = file;
}
}
private void buttonSelectOutput_Click(object sender, EventArgs e)
{
string defaultFileName = "HIBPBloomFilter.bin";
var openDialog = new SaveFileDialog();
openDialog.Filter = "All Files (*.*)|*.*";
openDialog.FileName = defaultFileName;
if (openDialog.ShowDialog() == DialogResult.OK)
{
string file = openDialog.FileName;
textBoxOutput.Text = file;
}
}
private void CreateBloomFilter_FormClosed(object sender, FormClosedEventArgs e)
{
cancellationTokenSource.Cancel();
}
private void buttonCancel_Click(object sender, EventArgs e)
{
cancellationTokenSource.Cancel();
Close();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
if (textBoxOutput.Text == string.Empty)
{
MessageBox.Show("Please specify an output file", "Output file not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var inputFile = textBoxInput.Text;
if (!File.Exists(inputFile))
{
throw new FileNotFoundException();
}
Bloom();
}
private void BloomWorker(IProgress progress, CancellationToken token)
{
progress.Report(1);
var lineCount = 0;
using (var reader = File.OpenText(textBoxInput.Text))
{
while (reader.ReadLine() != null)
{
lineCount++;
if (lineCount % (1024 * 1024) == 0)
{
if (token.IsCancellationRequested)
return;
}
}
}
//lineCount = 551509767;
var currentLine = 0;
var progressTick = lineCount / 100;
BloomFilter bloomFilter = new BloomFilter(lineCount, 0.001F);
progress.Report(5);
var inputFile = textBoxInput.Text;
using (var fs = File.OpenRead(inputFile))
using (var sr = new StreamReader(fs))
{
while (sr.EndOfStream == false)
{
var line = sr.ReadLine().Substring(0, 40);
bloomFilter.Add(line);
currentLine++;
if (currentLine % progressTick == 0)
{
progress.Report(5 + (int)(((double)currentLine) / lineCount * 90));
if (token.IsCancellationRequested)
{
return;
}
}
}
}
bloomFilter.Save(textBoxOutput.Text);
progress.Report(100);
}
private async void Bloom()
{
ToggleControls(enabled: false);
progressBar.Show();
stopwatch.Start();
timer.Start();
var progress = new Progress(percent =>
{
progressBar.Value = percent;
});
CancellationToken token = cancellationTokenSource.Token;
await Task.Run(() => BloomWorker(progress, token));
labelInfo.Text = "Bloom filter successfully generated in: " + stopwatch.Elapsed.ToString("hh\\:mm\\:ss");
timer.Stop();
stopwatch.Stop();
stopwatch.Reset();
progressBar.Value = 0;
progressBar.Hide();
ToggleControls(enabled: true);
}
private void TimerTick(object sender, EventArgs e)
{
labelInfo.Text = "Elapsed time: " + stopwatch.Elapsed.ToString("hh\\:mm\\:ss");
}
private void ToggleControls(bool enabled)
{
this.textBoxInput.Enabled = enabled;
this.textBoxOutput.Enabled = enabled;
this.buttonSelectInput.Enabled = enabled;
this.buttonSelectOutput.Enabled = enabled;
this.buttonCreate.Enabled = enabled;
}
}
}
HIBPOfflineCheck-1.7.11/HIBPOfflineCheck/CreateBloomFilter.resx 0000664 0000000 0000000 00000013102 14736317116 0024022 0 ustar 00root root 0000000 0000000
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089