Skip to content

Commit c386d01

Browse files
authored
Add files via upload
1 parent 6744381 commit c386d01

10 files changed

Lines changed: 535 additions & 0 deletions

App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="FileEncrypter.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:FileEncrypter"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

App.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Configuration;
2+
using System.Data;
3+
using System.Windows;
4+
5+
namespace FileEncrypter
6+
{
7+
/// <summary>
8+
/// Interaction logic for App.xaml
9+
/// </summary>
10+
public partial class App : Application
11+
{
12+
}
13+
14+
}

AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]

FileEncrypter.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net8.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<UseWPF>true</UseWPF>
9+
</PropertyGroup>
10+
11+
</Project>

FileEncrypter.csproj.user

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<_LastSelectedProfileId>C:\Users\SP\source\repos\FileEncrypterr\FileEncrypter\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
5+
</PropertyGroup>
6+
</Project>

IronWallCipher.cs

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Security.Cryptography;
5+
using System.Text;
6+
7+
public class IronWallCipher
8+
{
9+
// --- HELPER BIT OPERATIONS ---
10+
11+
// Rotates bits to the left (For Diffusion effect)
12+
private static byte RotateLeft(byte value, int count)
13+
{
14+
return (byte)((value << count) | (value >> (8 - count)));
15+
}
16+
17+
// Rotates bits to the right (For Decryption)
18+
private static byte RotateRight(byte value, int count)
19+
{
20+
return (byte)((value >> count) | (value << (8 - count)));
21+
}
22+
23+
// Derives a strong key from Password and Salt
24+
private static byte[] DeriveKey(string password, byte[] salt)
25+
{
26+
using (var sha256 = SHA256.Create())
27+
{
28+
var passwordBytes = Encoding.UTF8.GetBytes(password);
29+
var combined = new byte[passwordBytes.Length + salt.Length];
30+
Buffer.BlockCopy(passwordBytes, 0, combined, 0, passwordBytes.Length);
31+
Buffer.BlockCopy(salt, 0, combined, passwordBytes.Length, salt.Length);
32+
return sha256.ComputeHash(combined);
33+
}
34+
}
35+
36+
// --- ENCRYPTION ---
37+
public static byte[] Encrypt(byte[] data, string password)
38+
{
39+
// 1. Generate a unique random 'Salt' for each file
40+
byte[] salt = new byte[16];
41+
using (var rng = RandomNumberGenerator.Create())
42+
{
43+
rng.GetBytes(salt);
44+
}
45+
46+
// 2. Derive the key
47+
byte[] key = DeriveKey(password, salt);
48+
List<byte> result = new List<byte>();
49+
50+
// Prepend the Salt to the file (Needed for decryption)
51+
result.AddRange(salt);
52+
53+
byte currentKeyByte = key[0];
54+
55+
for (int i = 0; i < data.Length; i++)
56+
{
57+
byte b = data[i];
58+
59+
// LAYER 1: XOR (Confusion)
60+
b = (byte)(b ^ currentKeyByte);
61+
62+
// LAYER 2: Bit Rotation (Avalanche Effect)
63+
b = RotateLeft(b, 3);
64+
65+
// LAYER 3: Modular Addition (To break linearity)
66+
b = (byte)(b + key[i % key.Length]);
67+
68+
// LAYER 4: Chaining (Cipher Block Chaining - CBC style)
69+
// The previous encrypted byte affects the current one.
70+
// Even a 1-bit change at the start changes the entire file.
71+
if (i > 0)
72+
{
73+
// Get the last added element from Result list (Account for Salt length)
74+
byte previousEncryptedByte = result[result.Count - 1];
75+
b = (byte)(b ^ previousEncryptedByte);
76+
}
77+
78+
result.Add(b);
79+
80+
// Update the key at every step (Rolling Key)
81+
currentKeyByte = (byte)((currentKeyByte + 11) % 256);
82+
}
83+
84+
return result.ToArray();
85+
}
86+
87+
// --- DECRYPTION ---
88+
public static byte[] Decrypt(byte[] encryptedData, string password)
89+
{
90+
if (encryptedData.Length < 16) throw new Exception("Invalid or corrupted file format.");
91+
92+
// 1. Extract the Salt from the beginning
93+
byte[] salt = encryptedData.Take(16).ToArray();
94+
byte[] actualData = encryptedData.Skip(16).ToArray();
95+
96+
// 2. Re-derive the key
97+
byte[] key = DeriveKey(password, salt);
98+
99+
byte[] decrypted = new byte[actualData.Length];
100+
byte currentKeyByte = key[0];
101+
102+
for (int i = 0; i < actualData.Length; i++)
103+
{
104+
byte b = actualData[i];
105+
106+
// We need the previous encrypted data to reverse the chaining
107+
byte xorMask = 0;
108+
if (i > 0)
109+
{
110+
xorMask = actualData[i - 1];
111+
}
112+
113+
// PERFORM OPERATIONS IN REVERSE ORDER (Reverse Engineering)
114+
115+
// 4. Reverse Chaining
116+
if (i > 0)
117+
{
118+
b = (byte)(b ^ xorMask);
119+
}
120+
121+
// 3. Modular Subtraction
122+
b = (byte)(b - key[i % key.Length]);
123+
124+
// 2. Right Bit Rotation
125+
b = RotateRight(b, 3);
126+
127+
// 1. Reverse XOR
128+
b = (byte)(b ^ currentKeyByte);
129+
130+
decrypted[i] = b;
131+
132+
// Update key (Same logic as encryption)
133+
currentKeyByte = (byte)((currentKeyByte + 11) % 256);
134+
}
135+
136+
return decrypted;
137+
}
138+
}

MainWindow.xaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<Window x:Class="WpfApp1.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="RedLine Archiver" Height="540" Width="500"
5+
ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen">
6+
7+
<Grid Background="#2c3e50">
8+
<StackPanel Margin="20,20,20,10">
9+
10+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,0,0,3">
11+
<TextBlock Text="RU" Foreground="White" Cursor="Hand" MouseLeftButtonDown="ChangeLanguage_Click" Tag="RU" FontSize="14" FontWeight="Bold"/>
12+
<TextBlock Text=" | " Foreground="Gray" FontSize="14" Margin="5,0"/>
13+
<TextBlock Text="EN" Foreground="White" Cursor="Hand" MouseLeftButtonDown="ChangeLanguage_Click" Tag="EN" FontSize="14" FontWeight="Bold"/>
14+
<TextBlock Text=" | " Foreground="Gray" FontSize="14" Margin="5,0"/>
15+
<TextBlock Text="TR" Foreground="White" Cursor="Hand" MouseLeftButtonDown="ChangeLanguage_Click" Tag="TR" FontSize="14" FontWeight="Bold"/>
16+
</StackPanel>
17+
18+
<TextBlock Name="lblTitle" Text="REDLINE ARCHIVER" FontSize="28" FontWeight="Bold"
19+
HorizontalAlignment="Center" Foreground="#ecf0f1" FontFamily="Consolas"/>
20+
21+
<TextBlock Name="lblSubtitle" Text="Sıkıştırılmış Klasör Şifreleme Sistemi" FontSize="12"
22+
HorizontalAlignment="Center" Foreground="#bdc3c7" Margin="0,0,0,20"/>
23+
24+
<Border Name="dropZone" Height="150" Background="#34495e" CornerRadius="10"
25+
BorderBrush="#e74c3c" BorderThickness="2" AllowDrop="True" Drop="dropZone_Drop">
26+
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
27+
<TextBlock Text="📂" FontSize="40" HorizontalAlignment="Center"/>
28+
<TextBlock Name="txtDropInfo" Text="DOSYA VEYA KLASÖRÜ BURAYA SÜRÜKLE"
29+
Foreground="White" FontWeight="Bold" Margin="0,10,0,0"/>
30+
<TextBlock Name="txtSelectedPath" Text="..." Foreground="#95a5a6"
31+
FontSize="10" Margin="0,5,0,0" TextWrapping="Wrap" MaxWidth="400" HorizontalAlignment="Center"/>
32+
</StackPanel>
33+
</Border>
34+
35+
<TextBlock Name="lblEngine" Text="Şifreleme Motoru:" Foreground="#ecf0f1" Margin="0,15,0,5"/>
36+
<ComboBox Name="cmbAlgo" Height="30" SelectedIndex="4">
37+
<ComboBoxItem Content="AES-256 (Military Standard)"/>
38+
<ComboBoxItem Content="TripleDES"/>
39+
<ComboBoxItem Content="DES"/>
40+
<ComboBoxItem Content="RC2"/>
41+
<ComboBoxItem Content="REDLINE XOR (Custom Algorithm)"/>
42+
</ComboBox>
43+
44+
<TextBlock Name="lblPassword" Text="Şifre Belirle:" Foreground="#ecf0f1" Margin="0,10,0,5"/>
45+
<PasswordBox Name="txtPassword" Height="30" Margin="0,0,0,20" FontSize="16" HorizontalContentAlignment="Center"/>
46+
47+
<Grid>
48+
<Grid.ColumnDefinitions>
49+
<ColumnDefinition Width="*"/>
50+
<ColumnDefinition Width="*"/>
51+
</Grid.ColumnDefinitions>
52+
53+
<Button Name="btnEncrypt" Grid.Column="0" Content="🔒 SIKIŞTIR &amp; KİLİTLE" Height="50" Margin="0,0,5,0"
54+
Background="#c0392b" Foreground="White" FontWeight="Bold" FontSize="13" Click="Encrypt_Click" BorderThickness="0"/>
55+
56+
<Button Name="btnDecrypt" Grid.Column="1" Content="🔓 KİLİDİ AÇ &amp; ÇIKART" Height="50" Margin="5,0,0,0"
57+
Background="#27ae60" Foreground="White" FontWeight="Bold" FontSize="13" Click="Decrypt_Click" BorderThickness="0"/>
58+
</Grid>
59+
60+
<TextBlock Name="txtStatus" Text="Hazır." Foreground="#f1c40f"
61+
HorizontalAlignment="Center" Margin="0,15,0,0" FontWeight="Bold"/>
62+
</StackPanel>
63+
</Grid>
64+
</Window>

0 commit comments

Comments
 (0)