الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كود تشفير خوارزمية الaes بال++c

بدأه pink ghost في 12 يونيو 2011 · 6 رد · 2,516 مشاهدة · في قسم أمن المعلومات العام
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله تعالى وبركاته لقد كتبت كود تشفير لخوارزمية الAES ولكن لا اعرف اين الاخطاء

والكود هو

#include<iostream.h>
#include<stdio.h>
KeyExpansion (byte Key[4*Nk), word w[Nb*Nr+1)],Nk)
  {
    for (i = 0; i < Nk; i++)
      ExpandedKey = (CipherKey[4*i], CipherKey[4*i + 1],
         CipherKey[4*i + 2], CipherKey[4*i + 3]);
    for (i = Nk; i < Nb * (Nr + 1); i++)
    {
      temp = ExpandedKey[i - 1];
      if (i % Nk == 0)
         temp = ByteSub (RotByte (temp))^ Rcon[i/Nk];
      ExpandedKey = ExpandedKey[i - Nk] ^ temp;
    }
  }
 KeyExpansion (byte CipherKey, word ExpandedKey)
  {
    for (i = 0; i < Nk; i++)
      ExpandedKey = (CipherKey[4*i], CipherKey[4*i + 1],
              CipherKey[4*i + 2], CipherKey[4*i + 3]);

    for (i = Nk; i < Nb * (Nr + 1); i++)
    {
      temp = ExpandedKey[i - 1];
      if (i % Nk == 0)
         temp = ByteSub (RotByte (temp)) ^ Rcon[i/Nk];
      else if (itemp = ByteSub (temp);
      ExpandedKey = ExpandedKey[i - Nk] ^ temp;
    }
  }
 Round (word State, word RoundKey)
  {
    ByteSub (State);
    ShiftRow (State);
    MixColumn (State);
    AddRoundKey (State, RoundKey)
  }

  FinalRound (word State, word RoundKey)
  {
    ByteSub (State);
    ShiftRow (State);
    AddRoundKey (State, RoundKey)
  }
 AES (byte State, byte CipherKey)
  {
    KeyExpansion (CipherKey, ExpandedKey);
    AddRoundKey (State, ExpandedKey);
    for (i = 1; i < Nr; i++)
      Round (State, ExpandedKey + Nb*i);
    FinalRound (State, ExpandedKey + Nb*Nr);
  }
decryption()
 InvFinalRound (word State, word RoundKey)
  {
    AddRoundKey (State, RoundKey);
    InvShiftRow (State);
    InvByteSub (State);
  }

  InvRound (word State, word RoundKey)
  {
    AddRoundKey (State, RoundKey);
    InvMixColumn (State);
    InvShiftRow (State);
    InvByteSub (State);
  }
InvRijndael (byte State, byte CipherKey)
  {
    KeyExpansion (CipherKey, ExpandedKey);
    InvFinalRound (State, ExpandedKey + Nb*Nr);
    for (i = Nr - 1; i > 0; i--)
      InvRound (State, ExpandedKey + Nb*i);
    AddRoundKey (State, ExpandedKey);
  }
InvFinalRound (word State, word RoundKey)
  {
    AddRoundKey (State, RoundKey);
    InvByteSub (State);
    InvShiftRow (State);
  }

  InvRound (word State, word RoundKey)
  {
    InvMixColumn (State);
    AddRoundKey (State, MixColumn (RoundKey));
    InvByteSub (State);
    InvShiftRow (State);
  }
AddRoundKey (State, RoundKey);

  InvRound (word State, word RoundKey)
  {
    InvByteSub (State);
    InvShiftRow (State);
    InvMixColumn (State);
    AddRoundKey (State, MixColumn (RoundKey));
  }

  InvFinalRound (word State, word RoundKey)
  {
    InvByteSub (State);
    InvShiftRow (State);
    AddRoundKey (State, RoundKey)
  }
AddRoundKey (State, RoundKey);

  InvRound (word State, word RoundKey)
  {
    InvByteSub (State);
    InvShiftRow (State);
    InvMixColumn (State);
    AddRoundKey (State, MixColumn (RoundKey));
  }

  InvFinalRound (word State, word RoundKey)
  {
    InvByteSub (State);
    InvShiftRow (State);
    AddRoundKey (State, RoundKey)
  }
 InvRijndael (byte State, byte CipherKey)
  {
    InvKeyExpansion (CipherKey, InvExpandedKey);
    AddRoundKey (State, InvExpandedKey + Nb*Nr);
    for (i = Nr - 1; i > 0; i--)
      InvRound (State, InvExpandedKey + Nb*i);
    InvFinalRound (State, InvExpandedKey);
  }
return 0;
}
}

تم تعديل هذه المشاركة بواسطة محمد علاء الدين في 12 يونيو 2011 في 11:36 — السبب: تعديل تاج الكود

#2

هل انت متأكد ان هذا كود c++ ؟

مدونتي: C++ Tips and Tricks

#3

لقد وجدت الخوارزمية فى الكتاب الاصلى وقمت بتحويلها الى كود ++c

#4
اقتباس
لقد وجدت الخوارزمية فى الكتاب الاصلى وقمت بتحويلها الى كود ++c

جميل، و لكن يبدو انك وضعت الخوارزميه الأصليه و نسيت وضع كود ++c الذى قمت بتحويل الخوارزميه إليه؟

مدونتي: C++ Tips and Tricks

#5

:rolleyes: كلامك صح وآسفة على وجع الراس ولو عندك الصلاحية تنقل الموضوع لقسم امن المعلومات ممكن لانو الخوارزمية موضوعها حول الsecurity

#6

حالياً انا عملت الدالة الاولى فى البرنامج sub _box()ولا يوجد اخطاء بالبرنامج ولكن لا يعطى نتيجة

#include<iostream.h>
#include<conio.h>
int rr[4][4];
int Sub_Box[16][16] = {
					{99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118},
					{202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192},
					{183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21},
					{4,199,35,195,24,150,5,154,7,118,128,226,235,39,178,117},
					{9,131,44,27,27,110,90,160,82,59,214,179,41,227,47,132},
					{83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207},
					{208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168},
					{81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210},
					{205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115},
					{96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219},
					{224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121},
					{231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8},
					{186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138},
					{112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158},
					{225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223},
					{140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22}
					};
void bit()
	{
   int rows, cols;
   int new1[8],val;
   for (int a=0;a<=3;a++)
   	{
      for(int b=0;b<=3;b++)
      	{val = rr[a];
          for(int c=7;c>=0;c++)
          	{
            new1[c] = val%2;
            val =  val/2;
            }
         rows  = (new1[0]*8+new1[1]*4+new1[2]*2+new1[3]);
         cols  = (new1[4]*8+new1[5]*4+new1[6]*2+new1[7]);
         rr[a] = Sub_Box[rows][cols];
         }
      }
   }

void main()
	{
      char cc[16];
	cin>>cc;
   for(int s=0, j=0;j<=3;j++)
   	{
      for(int i=0;i<=3;i++)
      	{
            rr[j] = cc[s++];
         }
      }

   bit();
     for (int a=0;a<=3;a++)
   	{
      for(int b=0;b<=3;b++)
      	{
         cout<<rr[a]<<"  ";
         }
      cout<<"\n\n";
      }


   getch();
   }

تم تعديل هذه المشاركة بواسطة Xacker في 16 يونيو 2011 في 17:51

#7

نفسى اعرف ليه مش فى حد عاوز يساعدنى عل العموم متشكرة خالص على جهود المشرفين .

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…