• 0

need VB codes for aes or des to encryption


Question

6 answers to this question

Recommended Posts

  • 0

Well, I had to do des for homework,and I did it in C#. It's still a .net language and you shouldn't have to much trouble converting it to vb .net. Or at least it will help you understand the principle behind it. It's not the best written code since I rushed it a bit too much. And the functions only work with arrays of 8 bytes. You can get the bytes from any type with a built-in method or you can write your own method. And you can pack more things in 8 bytes and you should be fine as long as you keep them in the right order. Hope I didn't make any mistakes copying it. Good luck :).

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

public static class myDES
{
private static int[, ,] M = {
			   {{14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7},
				{ 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8},
				{ 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0},
				{15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13}},

			   {{15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10},
				{ 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5},
				{ 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15},
				{13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9}},

			   {{10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8},
				{13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1},
				{ 3, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7},
				{ 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12}},

			   {{ 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15},
				{13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9},
				{10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4},
				{ 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2, 4}},

			   {{ 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9},
				{14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6},
				{ 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14},
				{11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3}},

			   {{12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11},
				{10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8},
				{ 9,14,15, 5, 2 ,8,12, 3, 7, 0, 4,10, 1,13,11, 6},
				{ 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13}},

			   {{ 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1},
				{13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6},
				{ 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2},
				{ 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12}},

			   {{13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7},
				{ 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2},
				{ 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 2, 5, 8},
				{ 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11}}
			   };

		private static int[,] PC0 = {
								{58,50,42,34,26,18,10, 2},
								{60,52,44,36,28,20,12, 4},
								{62,54,46,38,30,22,14, 6},
								{64,56,48,40,32,24,16, 8},
								{57,49,41,33,25,17, 9, 1},
								{59,51,43,35,27,19,11, 3},
								{61,53,45,37,29,21,13, 5},
								{63,55,47,39,31,23,15, 7}
							};

		private static  int[,] PC0I = {
								 {40, 8,48,16,56,24,64,32},
								 {39, 7,47,15,55,23,63,31},
								 {38, 6,46,14,54,22,62,30},
								 {37, 5,45,13,53,21,61,29},
								 {36, 4,44,12,52,20,60,28},
								 {35, 3,43,11,51,19,59,27},
								 {34, 2,42,10,50,18,58,26},
								 {33, 1,41, 9,49,17,57,25}
							 };


		private static int[,] PC1 = {
					 {57,49,41,33,25,17, 9},
							 { 1,58,50,42,34,26,18},
					 {10, 2,59,51,43,35,27},
					 {19,11, 3,60,52,44,36},
					 {63,55,47,39,31,23,15},
					 { 7,62,54,46,38,30,22},
					 {14, 6,61,53,45,37,29},
					 {21,13, 5,28,20,12, 4}};

		private static int[,] PC2 ={
					{57,49,41,33,25,17, 9},
							{ 1,58,50,42,34,26,18},
					{10, 2,59,51,43,35,27},
					{19,11, 3,60,52,44,36},
					{63,55,47,39,31,23,15},
					{ 7,62,54,46,38,30,22},
					{14, 6,61,53,45,37,29},
					{21,13, 5,28,20,12, 4}};

		private static int[,] E ={
					  {32, 1, 2, 3, 4, 5},
					  { 4, 5, 6, 7, 8 ,9},
					  { 8, 9,10,11,12,13},
					  {12,13,14,15,16,17},
					  {16,17,18,19,20,21},
					  {20,21,22,23,24,25},
					  {24,25,26,27,28,29},
					  {28,29,30,31,32, 1}
				  };

		private static int[,] P = {
							  {16, 7,20,21},
							  {29,12,28,17},
							  { 1,15,23,26},
							  { 5,18,31,10},
							  { 2, 8,24,14},
							  {32,27, 3, 9},
							  {19,13,30, 6},
							  {22,11, 4,25}
						  };
public static byte[] encrypt(byte[] sequence, long key)
		{
			List<long> round_keys = new List<long>();
			round_keys = calculate_Round_Keys(key);
			long compress_64 = 0L;
			long permuted_64 = 0L;
			byte[] round_call = new byte[8];

			for (int j = 0; j < 8; j++)
			{
				compress_64 = compress_64 << 8;
				compress_64 = sequence[j] | compress_64;
			}
			for (int j = 0; j < 64; j++)
			{
				permuted_64 = permuted_64 << 1;
				permuted_64 = permuted_64 | ((compress_64 >> (64 - PC0[j / 8, j % 8])) & 1L);
			}
			for (int j = 7; j >= 0; j--)
			{
				round_call[j] = (byte)(permuted_64 & 255);
				permuted_64 = permuted_64 >> 8;
			}
			for (int j = 0; j < 16; j++)
			{
				round_call = this.encrypt_round(round_call, round_keys, j);
			}
			byte aux;
			aux = round_call[7];
			round_call[7] = round_call[3];
			round_call[3] = aux;
			aux = round_call[6];
			round_call[6] = round_call[2];
			round_call[2] = aux;
			aux = round_call[5];
			round_call[5] = round_call[1];
			round_call[1] = aux;
			aux = round_call[4];
			round_call[4] = round_call[0];
			round_call[0] = aux;
			compress_64 = 0L;
			for (int j = 0; j < 8; j++)
			{
				compress_64 = compress_64 << 8;
				compress_64 = round_call[j] | compress_64;
			}
			permuted_64 = 0L;
			for (int j = 0; j < 64; j++)
			{
				permuted_64 = permuted_64 << 1;
				permuted_64 = permuted_64 | ((compress_64 >> (64 - PC0I[j / 8, j % 8])) & 1L);
			}
			for (int j = 7; j >= 0; j--)
			{
				round_call[j] = (byte)(permuted_64 & 255);
				permuted_64 = permuted_64 >> 8;
			}
			return round_call;
		}

		public static byte[] decrypt(byte[] sequence, long key)
		{
			List<long> round_keys = new List<long>();
			round_keys = calculate_Round_Keys(key);
			long compress_64 = 0L;
			long permuted_64 = 0L;
			byte[] round_call = new byte[8];

			for (int j = 0; j < 8; j++)
			{
				compress_64 = compress_64 << 8;
				compress_64 = sequence[j] | compress_64;
			}
			for (int j = 0; j < 64; j++)
			{
				permuted_64 = permuted_64 << 1;
				permuted_64 = permuted_64 | ((compress_64 >> (64 - PC0[j / 8, j % 8])) & 1L);
			}
			for (int j = 7; j >= 0; j--)
			{
				round_call[j] = (byte)(permuted_64 & 255);
				permuted_64 = permuted_64 >> 8;
			}
			for (int j = 15; j >= 0; j--)
			{
				round_call = this.encrypt_round(round_call, round_keys, j);
			}
			byte aux;
			aux = round_call[7];
			round_call[7] = round_call[3];
			round_call[3] = aux;
			aux = round_call[6];
			round_call[6] = round_call[2];
			round_call[2] = aux;
			aux = round_call[5];
			round_call[5] = round_call[1];
			round_call[1] = aux;
			aux = round_call[4];
			round_call[4] = round_call[0];
			round_call[0] = aux;
			compress_64 = 0L;
			for (int j = 0; j < 8; j++)
			{
				compress_64 = compress_64 << 8;
				compress_64 = round_call[j] | compress_64;
			}
			permuted_64 = 0L;
			for (int j = 0; j < 64; j++)
			{
				permuted_64 = permuted_64 << 1;
				permuted_64 = permuted_64 | ((compress_64 >> (64 - PC0I[j / 8, j % 8])) & 1L);
			}
			for (int j = 7; j >= 0; j--)
			{
				round_call[j] = (byte)(permuted_64 & 255);
				permuted_64 = permuted_64 >> 8;
			}
			return round_call;
		}

		private static List<long> calculate_Round_Keys(long key)
		{
			List<long> ret = new List<long>();
			long key_64 = key;
			long key_56 = 0L;
			long key_48 = 0L;
			long key_first_28;
			long key_last_28;
			long key_56_aux;
			long mask_28 = 268435455; //2^28 - 1
			long mask_28_last = 72057593769492480;//2^56 - 1 - 2^28

			for (int i = 0; i < 56; i++)
			{
				key_56 = key_56 << 1;
				key_56 = key_56 | ((key_64 >> (64 - this.PC1[i / 8, i % 7])) & 1);
			}
			for (int i = 0; i < 16; i++)
			{
				key_last_28 = key_56 & mask_28;
				key_first_28 = (key_56 & mask_28_last) >> 28;

				for (int j = 0; j <= i; j++)
				{
					if (j == 0 || j == 1 || j == 8 || j == 15)
					{
						key_first_28 = key_first_28 << 1;
						key_first_28 = (key_first_28 & mask_28) | ((key_first_28 & ~mask_28) >> 28);
						key_last_28 = key_last_28 << 1;
						key_last_28 = (key_last_28 & mask_28) | ((key_last_28 & ~mask_28) >> 28);
					}
					else
					{
						key_first_28 = key_first_28 << 2;
						key_first_28 = (key_first_28 & mask_28) | ((key_first_28 & ~mask_28) >> 28);
						key_last_28 = key_last_28 << 2;
						key_last_28 = (key_last_28 & mask_28) | ((key_last_28 & ~mask_28) >> 28);   
					}
				}
				key_48 = 0L;
				key_56_aux = key_last_28 | (key_first_28 << 28);
				for (int j = 0; j < 48; j++)
				{
					key_48 = key_48 << 1;
					key_48 = key_48 | ((key_56_aux >> (56 - PC2[j / 8, j % 6])) & 1);
				}
				ret.Add(key_48);
			}
			return ret;
		}

		private byte[] encrypt_round(byte[] sequence, List<long> round_keys, int round)
		{
			byte[] ret = new byte[8];
			byte group_6;
			long expanded_48 = 0L;
			long substituted_32 = 0L;
			long permuted_32 = 0L;
			long aux_32 = 0L;
			long work_32 = 0L;
			long colums_4;
			long rows_2;

			ret[7] = sequence[3];
			ret[6] = sequence[2];
			ret[5] = sequence[1];
			ret[4] = sequence[0];

			work_32 = sequence[0] | work_32;
			work_32 = work_32 << 8;
			work_32 = sequence[1] | work_32;
			work_32 = work_32 << 8;
			work_32 = sequence[2] | work_32;
			work_32 = work_32 << 8;
			work_32 = sequence[3] | work_32;

			for (int i = 0; i < 48; i++)
			{
				expanded_48 = expanded_48 << 1;
				expanded_48 = expanded_48 | ((work_32 >> (32 - E[i / 8, i % 6])) & 1L);
			}
			expanded_48 = expanded_48 ^ round_keys[round];
			for (int i = 0; i < 8; i++)
			{
				substituted_32 = substituted_32 << 4;
				group_6 = (byte)((expanded_48 >> (48 - i * 6 - 6)) & 63);
				rows_2 = ((32 & group_6) >> 4) | (1 & group_6);
				colums_4 = (30 & group_6) >> 1;
				substituted_32 = substituted_32 | M[i, rows_2, colums_4];
			}

			aux_32 = 0L;
			aux_32 = aux_32 | sequence[4];
			aux_32 = aux_32 << 8;
			aux_32 = aux_32 | sequence[5];
			aux_32 = aux_32 << 8;
			aux_32 = aux_32 | sequence[6];
			aux_32 = aux_32 << 8;
			aux_32 = aux_32 | sequence[7];

			for (int i = 0; i < 32; i++)
			{
				permuted_32 = permuted_32 << 1;
				permuted_32 = permuted_32 | ((substituted_32 >> P[i / 8, i % 4]) & 1L);
			}

			substituted_32 = permuted_32 ^ aux_32;

			ret[3] = (byte)(substituted_32);
			substituted_32 = substituted_32 >> 8;
			ret[2] = (byte)(substituted_32);
			substituted_32 = substituted_32 >> 8;
			ret[1] = (byte)(substituted_32);
			substituted_32 = substituted_32 >> 8;
			ret[0] = (byte)(substituted_32);
			return ret;
		}
}

Edited by Cold Blood
  • 0

I want to do it with VB.NET to DES or AES or RSA.

like this:

Encrypts the content of a text file and stores the cipher in another text file.

Decrypts a cipher stored in a text file and stores the plain text in a text file.

Your program should read from the user the path of the cipher and the plain text along with the key and either he/she wishes to encrypt or decrypt.

You may use one of the following languages to develop your program: C++, JAVA or VB.NET.

If you got the help of any packages or ready code, pleas mention it and provide all the resource you've used.

You can chose on or more of these algorithms to encrypt or decrypt.

o DES.

o AES.

o RSA.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Camtasia 2026.1.3 by Razvan Serea TechSmith Camtasia is the complete professional solution for high-quality screen recording, video editing and sharing. Camtasia 2026 makes editing your videos easier, and faster than ever. The new editor is packed with enhanced video processing, all-new production technology, an innovative library, and stock videos and other creative assets to help you create more polished, professional videos. No video experience needed. Anyone can create informative, engaging videos. Create professional, eye-catching videos: Add special video effects - Apply Behaviors that are perfectly designed to animate your text, images, or icons. Get a crisp, polished look without being a professional video editor. Drag-and-drop your edits - What you see is what you get. Every effect and element in your video can be dropped and edited directly in the preview window. And you can edit at resolutions up to beautiful 4K, for clear video at any size. Get exceptional performance - Camtasia takes full advantage of your computer’s processor with 64-bit performance. You’ll get fast rendering times and enhanced stability—even on your most complex projects. Camtasia 2026.1.3 changelog: Feature Updates Improved keyboard navigability in tool panels. Improved screen reader accessibility of headings in Preferences. Tool panels can now be resized using a keyboard-navigable control. Updated color of folder icon in User Library tab for better visibility. Grouped media now render a composite waveform considering all audio media within that group. Added Long Path Aware to the manifest of Editor and Recorder. Performance Improvements Improved performance for editing groups on the timeline. Improved the project loading performance when timeline has lots of trec media with cursor data. Updates for IT Administrators Updated cpp-httplib from 0.38.0 to 0.43.3. Updated expat from 2.7.4 to 2.8.0. Updated freetype from 2.13.3 to 2.14.3. Updated harfbuzz from 13.0.1 to 14.2.0. Updated libpng16 from 1.6.55 to 1.6.58. Updated pango from 1.57.0 to 1.57.1. Updated girepository from 2.86.3 to 2.88.0. Updated pcre2-posix from 10.47.0 to 12.0.2. Added new harfbuzz-gpu.dll. Updated FFmpeg from 7.1.1 to 7.1.2. Updated aom from 3.11.0 to 3.13.1. Updated dav1d from 1.5.0 to 1.5.1. Updated ogg from 1.3.5 to 1.3.6. Updated SDL2 from 2.32.4 to 2.32.10. Updated zlib from 1.3.1 to 1.3.2. Updated Nalpeiron binaries to version 4.4.69.3. Bug Fixes Fixed an issue which prevented some user submitted crash reports from being sent. Fixed a potential memory leak when decoding HEVC or VP9 video. Fixed a potential crash when trying to delete a range selection on a magnetic track. Fixed a bug with the Properties Panel showing stale properties when only a caption is selected on the timeline. Fixed an issue that could prevent the Opacity and Blur properties from being changed in the Background Removal effect. Fixed an issue where larger Camtasia online projects may fail to open in Camtasia Editor. Table of contents thumbnails are no longer created for Smart Player exports with no table of contents. Fix resetting skew revert to revert just skew and not scale as well. Fixed editing in Snagit with snagX file with Unicode characters. Fixed a bug where grouped visual media could be cropped in some cases. Fixed importing SnagX files with Unicode characters. Localization fixes. Download: Camtasia 2026.1.3 | 309.0 MB (Shareware) View: Camtasia Homepage | Tutorials | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • yeah it seems to be Edge only. The dialog buttons work as expected in Chrome and Firefox. The phone is using Android 16 (OneUI 8.5) and Edge version  149.0.4022.53
    • I'm not aware of this issue, but to help the other guys.  What version of Android are you using? Did you try a different browser? To see if Edge is the issue here.
    • I agree when are you going to read this (really poor BTW) article? Here is a better article so you actually know what is going on and answers questions you had in other comments --> https://arstechnica.com/gadgets/2026/05/speed-boosting-low-latency-profile-is-one-of-the-improvements-coming-to-windows-11/ It is unclear if one will be able to disable the new profile at this point but I am not seeing any reason why one would.
  • Recent Achievements

    • One Month Later
      Jamswaz earned a badge
      One Month Later
    • Week One Done
      Jamswaz earned a badge
      Week One Done
    • Rookie
      Marzoid went up a rank
      Rookie
    • Community Regular
      coch went up a rank
      Community Regular
    • One Year In
      slackerzz earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      510
    2. 2
      PsYcHoKiLLa
      188
    3. 3
      +Edouard
      157
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!