Skip to content

Instantly share code, notes, and snippets.

@Gizmodo
Created January 18, 2017 19:43
Show Gist options
  • Save Gizmodo/b981435de95146cb5a18f66ce3ac6494 to your computer and use it in GitHub Desktop.
Save Gizmodo/b981435de95146cb5a18f66ce3ac6494 to your computer and use it in GitHub Desktop.
Bank list encodnig/decoding
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
namespace EncodeBanks
{
class Program
{
private const string filePath = "D:\\bank_new.txt";
private const string fileFullPath = "D:\\bank_encoded.txt";
public List<string> Emailadresses;
public static DataTable Emails;
static void Main()
{
if (!!true) { LoadBankList(); }
else { EncodeFile(); }
}
private static void EncodeFile()
{
StreamReader reader = null;
var FI = new FileInfo(filePath);
if (!FI.Exists)
{
Console.WriteLine("No file");
return;
}
try
{
reader = new StreamReader(filePath);
string clean = reader.ReadToEnd();
var encoded = "";
int curr_byte;
foreach (char symbol in clean)
{
curr_byte = 1251 - symbol;
encoded += (char)curr_byte;
}
byte[] byteArray = Encoding.UTF8.GetBytes(encoded);
using (StreamWriter outfile = new StreamWriter(fileFullPath))
{
outfile.Write(encoded);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
// Define other methods and classes here
private static void LoadBankList()
{
StreamReader SR = null;
var path = "D:";
var FI = new FileInfo(fileFullPath);
if (!FI.Exists)
{
Console.WriteLine("No file");
return;
}
try
{
SR = new StreamReader(fileFullPath);
//lets some decode file
var encoded = SR.ReadToEnd();
var decoded = "";
int curr_byte;
for (var i = 0; i < encoded.Length; i++)
{
// Console.WriteLine(i.ToString());
curr_byte = 1251 - encoded[i];
decoded += (char)curr_byte;
}
//MemoryStream stream = new MemoryStream(byteArray);
SR = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(decoded)));
Emails = new DataTable();
Emails.Columns.Add("name");
Emails.Columns.Add("email");
while (!SR.EndOfStream)
{
var s = "";
s = SR.ReadLine();
Console.WriteLine(s);
var NewRow = Emails.Rows.Add();
NewRow["name"] = s.Substring(0, s.IndexOf('|'));
NewRow["email"] = s.Substring(s.IndexOf('|') + 1);
}
//clbBanks.DataSource = Emails;
//clbBanks.DisplayMember = "name";
SR.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment