ExamCryptoJanvier/crypto/Form1.cs

137 lines
4.2 KiB
C#

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace crypto
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
updateKonachanPic(this.pictureBox1);
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void fbt_cryptage_Click(object sender, EventArgs e)
{
switch (fcb_typeCrypto.Text)
{
case "Dot Net":
AES_CRYPTO c = new AES_CRYPTO();
this.ftb_traiter.Text = c.Crypt(this.ftb_origine.Text, this.ftb_clef.Text);
break;
case "PERSO":
CryptoPerso d = new CryptoPerso();
this.ftb_traiter.Text = d.Crypt(this.ftb_origine.Text, this.ftb_clef.Text);
break;
default:
warn w = new warn();
w.Show();
break;
}
updateKonachanPic(this.pictureBox1);
}
public static void updateKonachanPic(PictureBox pictureBox)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://konachan.net/post.json?tags=order%3Arandom+rating:safe&limit=1");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if (response.CharacterSet == null)
{
readStream = new StreamReader(receiveStream);
}
else
{
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
}
string data = readStream.ReadToEnd();
JsonTextReader reader = new JsonTextReader(new StringReader(data));
List<KonachanPostJson> dataSet = JsonConvert.DeserializeObject<List<KonachanPostJson>>(data);
KonachanPostJson[] bla = dataSet.ToArray();
String t = bla[0].JpegUrl;
Console.WriteLine(t);
pictureBox.ImageLocation = "http:" + t;
response.Close();
readStream.Close();
}
pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void fcb_typeCrypto_SelectedIndexChanged(object sender, EventArgs e)
{
if(fcb_typeCrypto.Text == "wubba lubba dub dub")
{
SoundPlayer player = new SoundPlayer();
player.SoundLocation = @"Rick_and_Morty_Rameses_B_Psytrance_Remix_.wav";
player.Play();
}
}
private void fbt_decrypter_Click(object sender, EventArgs e)
{
switch (fcb_typeCrypto.Text)
{
case "Dot Net":
AES_CRYPTO c = new AES_CRYPTO();
this.ftb_traiter.Text = c.decryptage(this.ftb_origine.Text, this.ftb_clef.Text);
break;
case "PERSO":
CryptoPerso d = new CryptoPerso();
this.ftb_traiter.Text = d.decryptage(this.ftb_origine.Text, this.ftb_clef.Text);
break;
default:
warn w = new warn();
w.Show();
break;
}
updateKonachanPic(this.pictureBox1);
}
private void timer1_Tick(object sender, EventArgs e)
{
}
}
}