CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Program
{
public static void Main()
{
Console.WriteLine("Start RW");
GenerateMatrix m = new GenerateMatrix();
int[,] x = m.GetMatrix();
List<Point> list = m.GetPoints(x);
string pass = m.GetPassword(list);
Console.WriteLine("\nWynik:");
Console.WriteLine(pass);
Console.WriteLine("End RW");
}
public class Point
{
public int x = 0;
public int y = 0;
public int val = 0;
public string GetName()
{
//"X:"x.ToString() + " ,Y:" + y.ToString() + " ,Val:" + val.ToString(); // opcja nr milion 500 sto 900
return val.ToString(); //opcja nr 1
}
}
public class GenerateMatrix {
public int[,] GetMatrix() {
int[,] matrix = new int[16, 16];
Random rnd = new Random();
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
matrix[i, j] = rnd.Next(0, 6);
}
}
matrix[1, 7] = 6; matrix[4, 0] = 8; matrix[4, 7] = 4; matrix[5, 6] = 9; matrix[5, 14] = 10;
matrix[7, 4] = 6; matrix[7, 11] = 8; matrix[8, 8] = 6; matrix[9, 7] = 3; matrix[9, 12] = 5;
matrix[10, 4] = 7; matrix[10, 13] = 6; matrix[12, 7] = 8; matrix[13, 9] = 6; matrix[13, 12] = 7;
return matrix;
}
public string GetPassword(List<Point> sortedPoints) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < sortedPoints.Count; i++) {
string name = sortedPoints[i].GetName().ToLower();
result.Append(name[i % name.Length]);
}
var utf8 = Encoding.UTF8.GetBytes(result.ToString());
return string.Join("", utf8.Select(x => "\\x" + x.ToString("x2")));
}
//private List<Point> GetPoints(int[,] matrix) {
// List<Point> list = new List<Point>();
// /* ... */
// return list;
//}
public List<Point> GetPoints(int[,] matrix)
{
List<Point> list = new List<Point>();
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
list.Add(new Point() { x = i, y = j, val = matrix[i, j] });
}
}
return list;
}
}
}