Skip to content

Commit 0eef68e

Browse files
authored
Merge pull request #27 from nvalenne/V3.0
gg wp
2 parents a52ad6e + b310e4f commit 0eef68e

45 files changed

Lines changed: 5161 additions & 726 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ build/
1818

1919
# Visual Studio cache/options
2020
.vs/
21+

CryptoSoft/CryptoSoft.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
9+
<Authors>ProSoft</Authors>
10+
<Company>ProSoft</Company>
11+
<Product>CryptoSoft</Product>
12+
<AssemblyTitle>CryptoSoft</AssemblyTitle>
13+
</PropertyGroup>
14+
15+
</Project>

CryptoSoft/CryptoSoft.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CryptoSoft", "CryptoSoft.csproj", "{469BFE89-6C63-4155-B90A-6097F2FC70F0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{469BFE89-6C63-4155-B90A-6097F2FC70F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{469BFE89-6C63-4155-B90A-6097F2FC70F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{469BFE89-6C63-4155-B90A-6097F2FC70F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{469BFE89-6C63-4155-B90A-6097F2FC70F0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

CryptoSoft/FileManager.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Diagnostics;
2+
using System.Text;
3+
4+
namespace CryptoSoft;
5+
6+
/// <summary>
7+
/// File manager class
8+
/// This class is used to encrypt and decrypt files
9+
/// </summary>
10+
public class FileManager(string path, string key)
11+
{
12+
private string FilePath { get; } = path;
13+
private string Key { get; } = key;
14+
15+
/// <summary>
16+
/// check if the file exists
17+
/// </summary>
18+
private bool CheckFile()
19+
{
20+
if (File.Exists(FilePath))
21+
return true;
22+
23+
Console.WriteLine("File not found.");
24+
Thread.Sleep(1000);
25+
return false;
26+
}
27+
28+
/// <summary>
29+
/// Encrypts the file with xor encryption
30+
/// </summary>
31+
public int TransformFile()
32+
{
33+
if (!CheckFile()) return -1;
34+
Stopwatch stopwatch = Stopwatch.StartNew();
35+
var fileBytes = File.ReadAllBytes(FilePath);
36+
var keyBytes = ConvertToByte(Key);
37+
fileBytes = XorMethod(fileBytes, keyBytes);
38+
File.WriteAllBytes(FilePath, fileBytes);
39+
stopwatch.Stop();
40+
return (int)stopwatch.ElapsedMilliseconds;
41+
}
42+
43+
/// <summary>
44+
/// Convert a string in byte array
45+
/// </summary>
46+
/// <param name="text"></param>
47+
/// <returns></returns>
48+
private static byte[] ConvertToByte(string text)
49+
{
50+
return Encoding.UTF8.GetBytes(text);
51+
}
52+
53+
/// <summary>
54+
/// </summary>
55+
/// <param name="fileBytes">Bytes of the file to convert</param>
56+
/// <param name="keyBytes">Key to use</param>
57+
/// <returns>Bytes of the encrypted file</returns>
58+
private static byte[] XorMethod(IReadOnlyList<byte> fileBytes, IReadOnlyList<byte> keyBytes)
59+
{
60+
var result = new byte[fileBytes.Count];
61+
for (var i = 0; i < fileBytes.Count; i++)
62+
{
63+
result[i] = (byte)(fileBytes[i] ^ keyBytes[i % keyBytes.Count]);
64+
}
65+
66+
return result;
67+
}
68+
}

CryptoSoft/Program.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace CryptoSoft;
2+
using System.Threading;
3+
4+
public static class Program
5+
{
6+
//on nomme le mutex pour qu'il soit global au niveau du système et donc partagé entre tous les processus
7+
private static readonly Mutex _mutex = new Mutex(false,"Global\\CryptoSoft_MonoInstance");
8+
public static void Main(string[] args)
9+
{
10+
11+
if (!_mutex.WaitOne(TimeSpan.Zero, true))
12+
{
13+
//si un autre processus à le mutex on quitte le programme
14+
Environment.Exit(-1);
15+
return;
16+
}
17+
try
18+
{
19+
foreach (var arg in args)
20+
{
21+
Console.WriteLine(arg);
22+
}
23+
24+
var fileManager = new FileManager(args[0], args[1]);
25+
int ElapsedTime = fileManager.TransformFile();
26+
Environment.Exit(ElapsedTime);
27+
}
28+
catch (Exception e)
29+
{
30+
Console.WriteLine(e.Message);
31+
Environment.Exit(-99);
32+
}
33+
finally
34+
{
35+
_mutex.ReleaseMutex();
36+
}
37+
}
38+
}

EasySaveSoft.slnx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
<Project Path="core/core.csproj">
1010
<BuildDependency Project="log/log.csproj" />
1111
</Project>
12+
<Project Path="CryptoSoft/CryptoSoft.csproj" />
13+
<Project Path="GUI/GUI.csproj" />
1214
<Project Path="log/log.csproj" Id="1c791ddd-50df-4686-8595-a855bf1bc5a0" />
1315
</Solution>

GUI/App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="GUITest.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:GUITest">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>

GUI/App.xaml.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using core.ViewModels;
2+
using System.Windows;
3+
4+
namespace GUITest
5+
{
6+
/// <summary>
7+
/// Interaction logic for App.xaml
8+
/// </summary>
9+
public partial class App : Application
10+
{
11+
public static MainViewModel ViewModel { get; set; }
12+
protected override void OnStartup(StartupEventArgs e)
13+
{
14+
ViewModel = new MainViewModel();
15+
View v = new View();
16+
ViewModel.OnSuccessOccurred += (msg) => v.ShowSuccess(msg);
17+
ViewModel.OnErrorOccurred += (msg) => v.ShowError(msg);
18+
MainWindow mainWindow = new MainWindow();
19+
base.OnStartup(e);
20+
mainWindow.Show();
21+
}
22+
23+
protected override void OnExit(ExitEventArgs e)
24+
{
25+
base.OnExit(e);
26+
// Ici, vous pouvez effectuer des actions de nettoyage ou de sauvegarde avant que l'application ne se ferme
27+
}
28+
}
29+
}

GUI/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+
)]

GUI/Assets/logo.png

106 KB
Loading

0 commit comments

Comments
 (0)