0% found this document useful (0 votes)
18 views3 pages

Labo 6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Labo 6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace spiral
{
class Program
{
static void Main(string[] args)
{
string s = ReadLine();
////Shifreleme////

byte[] b = Encoding.UTF8.GetBytes(s);
int n = b.Length;
int w = 0, h = 0; //acarlar
bool bb = false;
for(int i1 = 1;i1<n ; i1++)
{
for (int j1 = 1; j1 < n; j1++)
{
if (4 * i1 * j1 >= n + 4 && 2 * i1 >= 4)
{
w = 2 * i1;
h = 2 * j1;
bb = true;
break;
}
}
if (bb)
{
break;
}
}
byte[,] b1 = new byte[h, w];
for(int i1 = 0; i1 < b.Length; i1++)
{
b1[i1 / w, i1 % w] = b[i1];
}

int x0, x1, x2, x3;


x3 = n & 0xFF;
n >>= 8;
x2 = n & 0xFF;
n >>= 8;
x1 = n & 0xFF;
x0 = n >> 8;
b1[h - 1, w - 4] = (byte)x0;
b1[h - 1, w - 3] = (byte)x1;
b1[h - 1, w - 2] = (byte)x2;
b1[h - 1, w - 1] = (byte)x3;
int S = 0;
int countw = w, counth = h - 1;
int i = 0, j = 0;
b = new byte[w * h];
while (S < b.Length)
{
for (int k = 1; k <= countw; k++)
{
b[S] = b1[i, j];
j++;
S++;
}
j--;
countw--;
for (int k = 1; k <= counth; k++)
{
i++;
b[S] = b1[i, j];
S++;
}
counth--;
for (int k = 1; k <= countw; k++)
{
j--;
b[S] = b1[i, j];
S++;
}
for (int k = 1; k <= counth; k++)
{
i--;
b[S] = b1[i, j];
S++;
}
countw--;
counth--;
j++;
}
string ss = Encoding.UTF8.GetString(b);
WriteLine("Shifreli metn: " + ss);

////Deshifreleme/////

byte[,] b3 = new byte[h, w];


byte[] b2 = Encoding.UTF8.GetBytes(ss);
n = b2.Length;
countw = w;
counth = h - 1;
S = 0;
i = 0;
j = 0;
while (S < n)
{
for (int k = 1; k <= countw; k++)
{
b3[i, j] = b2[S];
j++;
S++;
}
j--;
countw--;
for (int k = 1; k <= counth; k++)
{
i++;
b3[i, j] = b2[S];
S++;
}
counth--;
for (int k = 1; k <= countw; k++)
{
j--;
b3[i, j] = b2[S];
S++;
}
for (int k = 1; k <= counth; k++)
{
i--;
b3[i, j] = b2[S];
S++;
}
countw--;
counth--;
j++;
}
int l = b3[h - 1, w - 4] << 24 | b3[h - 1, w - 3] << 16 | b3[h - 1, w - 2] << 8 |
b3[h - 1, w - 1];
b2 = new byte[l];
for (int i1 = 0; i1 < l; i1++)
{
b2[i1] = b3[i1 / w, i1 % w];
}
ss = Encoding.UTF8.GetString(b2);
WriteLine("Deshifre olunmush metn: " + ss);
ReadKey();
}
}
}

You might also like