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

Crack A Symmetric Key For A Tea Algorithm

بدأه sawsan87 في 10 أكتوبر 2008 · 15 رد · 2,580 مشاهدة · في لغة C و ++C
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

hi everyone..i need to crack a symmetric key by implementing a method called CrackSymmetricKey

I must use the TEA encryption algorithm below:



union myMsgType{

unsigned long textConverted[2];

char text[9];

};



class TEA_Algorithm

{

public:

void CrackSymmetricKey(union myMsgType plaintext, union myMsgType ciphertext);

void Decrypt(unsigned long k[], unsigned long ciphertext[], unsigned long plaintext[]);

void Encrypt(unsigned long k[], unsigned long plaintext[], unsigned long ciphertext[]);

TEA_Algorithm() {};

virtual ~TEA_Algorithm() {};



};

As input, im given the following ciphertext and i need to find the secret key that has been used to obtain this ciphertext, and hence, deduce the original plaintext.



// myCiphertext.textConverted[0] = 2022673309;

// myCiphertext.textConverted[1] = 3810199360;



/*

plaintext:= security

ciphertext:

myCiphertext.textConverted[0] = 2022673309;

myCiphertext.textConverted[1] = 3810199360;



additional information: key[0]=key[1]=k[2]=k[3]

and im asked to determine what is the secret key that

has been used to encrypt this plaintext.

*/

Can someone help me plz?

تم تعديل هذه المشاركة بواسطة HGB في 15 أكتوبر 2008 في 01:31

#2

اذا كنت تعلم طريقه التشفير والفك ، فمسأله معرفه المفتاح لن يكون بهذه الصعوبه .. يعني لو فرضنا التشفير كان بجمع رقم ما ، والطرح أيضا بنفس الرقم (لأنهم Symmetric) ، الأن لدى النص الأصلي كان A ، والنص المشفر كان C اذا بالتأكيد المفتاح سوف يكون 2 ..

أما لو الخوارزميه Implementation كانت غير معروفه ، فلن تستطيع كسرها الا لو كنت Cryptanalysis :) . لأنك ستحتاج الى هجوم Known-plaintext attack وهو ضعيف جدا أيضا ، يعني أحتمال ضيئل جدا لكي تكسر شيء بهذه الطريقه ، الا لو كانت الشفره هي قيصر :) .

على العموم ، هل الخوارزميه هي نفسها Tiny Encryption Algorithm ، في حاله كانت كذلك ، عليك بمعرفه طريقه التشفير ، حتى تستطيع كتابه الداله الخاص بالكسر .. واذا كانت غيرها فما هي طريقه التشفير المتسخدمه ..

بالتوفيق ،،

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#3
Wajdy Essam كتب:

اذا كنت تعلم طريقه التشفير والفك ، فمسأله معرفه المفتاح لن يكون بهذه الصعوبه .. يعني لو فرضنا التشفير كان بجمع رقم ما ، والطرح أيضا بنفس الرقم (لأنهم Symmetric) ، الأن لدى النص الأصلي كان A ، والنص المشفر كان C اذا بالتأكيد المفتاح سوف يكون 2 ..

أما لو الخوارزميه Implementation كانت غير معروفه ، فلن تستطيع كسرها الا لو كنت Cryptanalysis :) . لأنك ستحتاج الى هجوم Known-plaintext attack وهو ضعيف جدا أيضا ، يعني أحتمال ضيئل جدا لكي تكسر شيء بهذه الطريقه ، الا لو كانت الشفره هي قيصر :) .

على العموم ، هل الخوارزميه هي نفسها Tiny Encryption Algorithm ، في حاله كانت كذلك ، عليك بمعرفه طريقه التشفير ، حتى تستطيع كتابه الداله الخاص بالكسر .. واذا كانت غيرها فما هي طريقه التشفير المتسخدمه ..

بالتوفيق ،،

what i used for encryption is the following:

void TEA_Algorithm::Encrypt(unsigned long k[], unsigned long plaintext[], unsigned long ciphertext[])
{
unsigned long y = plaintext[0], z = plaintext[1];
 unsigned long delta = 0x9e3779b9, sum = 0; int n;
 for (n= 0; n < 32; n++) {
  sum += delta;
  y += ((z << 4) + k[0]) ^ (z+sum) ^ ((z >> 5) + k[1]);        
  z += ((y << 4) + k[2]) ^ (y+sum) ^ ((y >> 5) + k[3]);        
 }
 ciphertext[0] = y;  ciphertext[1] = z; 

}

and for decryption i used:

void TEA_Algorithm::Decrypt(unsigned long k[], unsigned long ciphertext[], unsigned long plaintext[])
{
unsigned long y = ciphertext[0], z = ciphertext[1];
 unsigned long delta = 0x9e3779b9, sum = delta << 5;  int n;
 for (n= 0; n < 32; n++) {
  z -= ((y << 4) + k[2]) ^ (y + sum) ^ ((y >> 5) + k[3]);
  y -= ((z << 4) + k[0]) ^ (z + sum) ^ ((z >> 5) + k[1]);
  sum -= delta;
 }
 plaintext[0] = y; plaintext[1] = z;
}
#4

صراحة لم أفهم ما يجري، يعني أرى خوارزمية التشفير وفك التشفير كتبتيها بنفسك، ما المشكلة او ما المطلوب إذاً؟

TEA نعم هي نفسها التي ذكرت أخ وجدي أكيد لا تقصد سواها.

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

#5

أهلا أخي Xacker ،

المطلوب كتابه داله تستقبل النص الأصلي والمشفر ، وتقوم الداله بمعرفه المفتاح ...

void CrackSymmetricKey(union myMsgType plaintext, union myMsgType ciphertext);

السؤال هنا ما الحاجه لأستخدام myMsgType (من نوع Union) ، لماذا لم تستخدم unsigned long كما في داله التشفير والفك .. الذي أعلمه عن Union أنه مثل السجل Struct لكن فقط قيمه واحده من المتغيرات داخله تكون Active ، يعني فقط نتعامل مع متغير واحد داخل هذه الUnion ... فلذلك لا أعرف لما تم أستخدامه هنا ..

أيضا أتمنى أن توضح مثال على كيفيه التشفير ، يعني النص هو X ، المفتاح هو Y ، الناتج هو Z .. الغرض فقط أن نعرف هل هناك طول محدد لكل من المفتاح والنص أم لأ ..

*تعديل : المفتاح بطول 128 بت ، يعني 4 خانات في المصفوفه long .

بالتوفيق ،

تم تعديل هذه المشاركة بواسطة Wajdy Essam في 10 أكتوبر 2008 في 21:30

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#6

حصل لي OverFlow :) ..

الخوارزميه TEA أول مره أشاهدها ، و يبدوا أنها من أسهل الشفرات ، نظريا وتطبيقيا ،،

على العموم لم لا تستخدم Brute-Force Method ، أسهل الطرق في مثل هذه الحالات ،،

سأتوقف الان ، ربما أكمل غدا ان شاء الله ،،

بالتوفيق ،،

اضافه الرابط ، يحتوي على pseudo-code وشرح مبسط لBrute-Force ،لكن على نسخه معدله من TEA ، المهم راح يفيدك كثير ..وهو برضه assignment :)

Breaking Double Weak Tea

تم تعديل هذه المشاركة بواسطة Wajdy Essam في 11 أكتوبر 2008 في 00:26

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#7

انا المفروض املي خطوات الكود ..عملت ال

encryption

وال

decryption

بصعوبة كبيرة و بمساعدة من دكتوري..بس هلا ما عارفة كيف اطلع ال

symantic key

الي بعرفه انو لازم اعمل لوب انو تظل تحاول لتطلعلي المفتاح بس ما عارفة اعمله

هاد هو الكود


#include <iostream>
#include <string.h>
using namespace std;
#include "TEA_Algorithm.h"
void TEA_Algorithm::Encrypt(unsigned long k[], unsigned long plaintext[], unsigned long ciphertext[])
{
unsigned long y = plaintext[0], z = plaintext[1];
unsigned long delta = 0x9e3779b9, sum = 0; int n;
for (n= 0; n < 32; n++) {
sum += delta;
y += ((z << 4) + k[0]) ^ (z+sum) ^ ((z >> 5) + k[1]);
z += ((y << 4) + k[2]) ^ (y+sum) ^ ((y >> 5) + k[3]);
}
ciphertext[0] = y; ciphertext[1] = z;
}
void TEA_Algorithm::Decrypt(unsigned long k[], unsigned long ciphertext[], unsigned long plaintext[])
{
unsigned long y = ciphertext[0], z = ciphertext[1];
unsigned long delta = 0x9e3779b9, sum = delta << 5; int n;
for (n= 0; n < 32; n++) {
z -= ((y << 4) + k[2]) ^ (y + sum) ^ ((y >> 5) + k[3]);
y -= ((z << 4) + k[0]) ^ (z + sum) ^ ((z >> 5) + k[1]);
sum -= delta;
}
plaintext[0] = y; plaintext[1] = z;
}
void TEA_Algorithm::CrackSymmetricKey(union myMsgType plaintext, union myMsgType ciphertext)
{
void CrackSymmetricKey(union c);
/*
You're given the following informatin:
plaintext:= security
ciphertext:
myCiphertext.textConverted[0] = 2022673309;
myCiphertext.textConverted[1] = 3810199360;
additional information: key[0]=key[1]=k[2]=k[3]
and you're asked to determine what is the secret key that
has been used to encrypt this plaintext.
*/
}
#include "stdafx.h"

lab1_ite408.zip

تم تعديل هذه المشاركة بواسطة sawsan87 في 11 أكتوبر 2008 في 08:50

#8

شكراً على التوضيح أخ وجدي،

لكن أجد تعارض بين ما ذكرت وبين هذه الجملة في الأعلى

اقتباس
As input, im given the following ciphertext and i need to find the secret key that has been used to obtain this ciphertext, and hence, deduce the original plaintext.

فكما أرى المطلوب هو الحصول على المفتاح السري + النص الأصلي من النص المشفر بمعرفة خوارزمية التشفير فقط.

طريقة BF ربما تكون هي الأبسط للتنفيذ لكن قد يكون هناك هجمات أفضل، يقال عن الموضح في الرابط التالي أنه الأفضل:

http://citeseerx.ist.psu.edu/viewdoc/downl...p1&type=pdf

تم تعديل هذه المشاركة بواسطة Xacker في 11 أكتوبر 2008 في 13:51

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

#9

Xacker أنظر لهذه العباره الغامضه :) في الرد الأول :

plaintext := security

ciphertext:

myCiphertext.textConverted[0] = 2022673309;

myCiphertext.textConverted[1] = 3810199360 ;

المفاتيح كلها متشابه ، أي بنفس القيمه :

: key[0]=key[1]=k[2]=k[3]

and you're asked to determine what is the secret key that

has been used to encrypt this plaintext.

يعني هو لديه النص الأصلي security ، ولديه الناتج المشفر ، ويحتاج أن يعرف المفتاح ،،

اذا عليه أن يجرب المفاتيح التاليه :

0 0 0 0

1 0 0 0

2 0 0 0

وهكذا ...

وفي كل مره يستدعي داله التشفير بالمفتاح الحالي مع النص security ، وقارن الناتج هل هو يساوي :

myCiphertext.textConverted[0] = 2022673309;

myCiphertext.textConverted[1] = 3810199360 ;

فاذا كان كذلك ، فخلاص تكون عرفت الرقم ، وأخرج من الحلقه أو الداله ، غير ذلك أستمر في البحث ..

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#10

كتبت داله لعمليه الـ Brute-Forcing ، ومفتاح الـTEA بطول 128 ، وطبعا يستحيل أن نكسر مثل هذا المفتاح لأن مدى البحث كبيييييييير جدا ، لكن في السؤال مكتوب أن المفتاح متشابه ، يعني كل المفاتيح في المصفوفه من 4 خانات متساويين .. وهذا قلل مدى البحث الى 2 اس 32 . أي هناك 4294967295 محاوله (0xFFFFFFFF) .

يمكن أن نستخدم الـ Threads لمثل هكذا أمر طبعا وسوف يقلل من العمليه ، كنت قد كتبت مثال بجافا ، على عمليه Brute-Force باستخدام أكثر من Threads (موجود في قسم الجافا) ..

حاليا عملت نسختين واحد تبدأ من 0x00000001وتكمل الى أن تجد المفتاح ، والنسخه التانيه تبدأ من 0xFFFFFFFF متناقصه طبعا الى أن تجد المفتاح ،،

ان شاء الله يضبط ، مع أن الـ CPU قرب ينفجر :P

post-51148-1223731185_thumb.png

في حال أنتهت العمليه بشكل سريع كان بها ، والا سأضع الداله وبعدين مشكلتكم في أنتظارها :P

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#11

يا جماعة حكالنا الدكتور انها كتير بسيطة

اتوقع حتبلش هيك

void CrackSymmetricKey(union c);

c=ciphertext

if c=plain text then exit the loop..the key is found

if c != plaintext then we have to increment the key

ممكن هلا حدا يساعدني اطبق هالشي الي كتبته او لا؟

تم تعديل هذه المشاركة بواسطة sawsan87 في 11 أكتوبر 2008 في 21:00

#12

لا أظن بوجود طريقه "فعاله"أخرى غير هذه ،، الا لو كانت هناك معلومات ومعطيات أخرى في البرنامج لا نعرفها ،،

عل كلِ ، هذه الداله التي قمت بكتابتها ، وسوف تستمر بالبحث من المفتاح 1 ، وكل مره تقوم بتشفير النص الأصلي ،وبعدها تقارن النص المشفر بـالقيمه الموجوده في السؤال ، فاذا تساوى فمعناه المفتاح الحالي هو الصحيح ونخرج من الحلقه ، والا فنقوم بزياده المفتاح بواحد ، ونستمر هكذا ...

 

[color= #0000ff;]void TEA_Algorithm[color= #000000;]:: [color= #808000;]CrackSymmetricKey[color= #000000;](

[color= #0000ff;]union myMsgType plaintext, [color= #0000ff;]union myMsgType ciphertext[color= #000000;])

[color= #000000;]{

[color= #0000ff;]bool state [color= #000000;]= [color= #0000ff;]true ;

[color= #0000ff;]unsigned [color= #0000ff;]long key[color= #000000;][[color= #ff0000;]4[color= #000000;]] [color= #000000;]= [color= #000000;]{0x00000001[color= #000000;]} ;

[color= #0000ff;]union myMsgType myPlaintext [color= #000000;]=  plaintext, 

 myCiphertext[color= #000000;]= ciphertext ;

 

	[color= #0000ff;]while [color= #000000;]( state [color= #000000;])

	[color= #000000;]{

Encrypt[color= #000000;](key, myPlaintext.[color= #808000;]textConverted,

 myCiphertext.[color= #808000;]textConverted[color= #000000;]);

 

	[color= #0000ff;]if  [color= #000000;]( [color= #000000;](myCiphertext.[color= #808000;]textConverted[color= #000000;][[color= #ff0000;]0[color= #000000;]] [color= #000000;]== 0x788F8B9D[color= #000000;]) [color= #000000;]&&

	  [color= #000000;](myCiphertext.[color= #808000;]textConverted[color= #000000;][[color= #ff0000;]1[color= #000000;]] [color= #000000;]== 0xE31B0740[color= #000000;]) [color= #000000;])

	[color= #000000;]{

	           state [color= #000000;]= [color= #0000ff;]false ;

	            [color= #0000ff;]break ;

	[color= #000000;]}

	key[color= #000000;][[color= #ff0000;]0[color= #000000;]][color= #000000;]++ ;

	key[color= #000000;][[color= #ff0000;]1[color= #000000;]][color= #000000;]++ ;

	key[color= #000000;][[color= #ff0000;]2[color= #000000;]][color= #000000;]++ ;

	key[color= #000000;][[color= #ff0000;]3[color= #000000;]][color= #000000;]++ ;

	[color= #000000;]}

 

	[color= #0000ff;]if [color= #000000;]( [color= #000000;]!state [color= #000000;])

	[color= #000000;]{

cout [color= #000000;]<< [color= #A31515;]"Ciphertext: " [color= #000000;]<< myCiphertext.[color= #808000;]text [color= #000000;]<< [color= #A31515;]" (" 

[color= #000000;]<< myCiphertext.[color= #808000;]textConverted[color= #000000;][[color= #ff0000;]0[color= #000000;]] [color= #000000;]<<

 [color= #A31515;]"," [color= #000000;]<< myCiphertext.[color= #808000;]textConverted[color= #000000;][[color= #ff0000;]1[color= #000000;]] [color= #000000;]<< [color= #A31515;]")";

 

cout [color= #000000;]<< [color= #A31515;]"n" [color= #000000;]<< key[color= #000000;][[color= #ff0000;]0[color= #000000;]] [color= #000000;]<< [color= #A31515;]" " [color= #000000;]<< key[color= #000000;][[color= #ff0000;]1[color= #000000;]] [color= #000000;]<< 

[color= #A31515;]" " [color= #000000;]<< key[color= #000000;][[color= #ff0000;]2[color= #000000;]] [color= #000000;]<< [color= #A31515;]" " [color= #000000;]<< key[color= #000000;][[color= #ff0000;]3[color= #000000;]] [color= #000000;]<< [color= #A31515;]"n" ;

 

	[color= #000000;]}

	[color= #0000ff;]else

	cout [color= #000000;]<< [color= #A31515;]"Cant Reach Here  n" ;

[color= #000000;]}

ربما تعمل ، وربما لا تعمل :) ، الله أعلم ،،

تم تعديل هذه المشاركة بواسطة Wajdy Essam في 11 أكتوبر 2008 في 20:49

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#13

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

بتشكرك كتير عالمساعدة مرة تانية وجزاك الله خير

#14

الـ key المستخدم في التشفير على ما يبدو: 2748

أرجو اختبار هذا من خلال دالة فك التشفير التي تقومين باستخدامها.

حصلت على الـ Key بعد كتابة الخوارزمية حسب ما فهمتها بكود أسمبلي. لا أدري لماذا لم يحصل الأخ وجدي على القيمة نفسها ببرنامجه فحسب فهمي البسيط للـ C الطريقة نفسها.

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

#15

Nice Job Xacker :wink:

فعلا الرقم صحيح ، ويخرج في أقل من ثانيه :) .

اقتباس
لا أدري لماذا لم يحصل الأخ وجدي على القيمة نفسها ببرنامجه فحسب فهمي البسيط للـ C الطريقة نفسها.

هي صحيحه لكن هناك مشكله بسيطه ، وهي أني هيئت العنصر الأول في المصفوفه بالمفتاح ، والباقي كانوا كلهم صفر ، ولذلك العمليه أصبحت خاطئه (مفتاح يختلف عن البقيه)

لذلك في الخوارزميه نفسها ، لكن غير السطر الأول في الداله :

unsigned long key[4] = {0x00000001};

بـ :

unsigned long key[4] = {0x00000001,0x00000001,0x00000001,0x00000001};

طبعا خطأ قاتل لا يغفر أبدا :S :S ، سأعتزل التشفير وسي++ أيضا :P

وهذا الكود كامل ، لمن أراد :

#include <iostream>
using namespace std;

union myMsgType
{
	unsigned long textConverted[2];
	char text[9];
};

class TEA_Algorithm 
{
	public:
		void CrackSymmetricKey(union myMsgType plaintext, union myMsgType ciphertext);
		void Decrypt(unsigned long k[], unsigned long ciphertext[], unsigned long plaintext[]);
		void Encrypt(unsigned long k[], unsigned long plaintext[], unsigned long ciphertext[]);

		TEA_Algorithm() {};
		virtual ~TEA_Algorithm() {};
};

void TEA_Algorithm::Encrypt(unsigned long k[], unsigned long plaintext[], unsigned long ciphertext[])
{
	unsigned long y = plaintext[0], z = plaintext[1]; 
	unsigned long delta = 0x9e3779b9, sum = 0;

	for (int n= 0; n < 32; n++) 
	{
		sum += delta;  
		y += ((z << 4) + k[0]) ^ (z+sum) ^ ((z >> 5) + k[1]);		  
		z += ((y << 4) + k[2]) ^ (y+sum) ^ ((y >> 5) + k[3]);   
	} 

	ciphertext[0] = y;  
	ciphertext[1] = z; 
}

void TEA_Algorithm::Decrypt(unsigned long k[], unsigned long ciphertext[], unsigned long plaintext[])
{
	unsigned long y = ciphertext[0], z = ciphertext[1]; 
	unsigned long delta = 0x9e3779b9, sum = 0xC6EF3720;  
	int n; 

	for (n= 0; n < 32; n++) 
	{  
		z -= ((y << 4) + k[2]) ^ (y + sum) ^ ((y >> 5) + k[3]);  
		y -= ((z << 4) + k[0]) ^ (z + sum) ^ ((z >> 5) + k[1]);  
		sum -= delta; 
	} 

	plaintext[0] = y; 
	plaintext[1] = z;
}

void TEA_Algorithm:: CrackSymmetricKey(union myMsgType plaintext, union myMsgType ciphertext)
{
	bool state = true;
	unsigned long key[4] = {0x00000001,0x00000001,0x00000001,0x00000001};

	union myMsgType myPlaintext =  plaintext,  myCiphertext= ciphertext;

	while ( state )
	{
		Encrypt(key, myPlaintext.textConverted, myCiphertext.textConverted);

		if  ( (myCiphertext.textConverted[0] == 0x788F8B9D) &&
			  (myCiphertext.textConverted[1] == 0xE31B0740) )
		{
			state = false;
			break;
		}
		key[0]++;
		key[1]++;
		key[2]++;
		key[3]++;
	}

	if ( !state )
	{
		cout << "Ciphertext: " << myCiphertext.text << " (" << myCiphertext.textConverted[0] << "," << myCiphertext.textConverted[1] << ")";
		cout << "\n" << key[0] << " " << key[1] << " " << key[2] << " " << key[3] << "\n";
	}
	else
		cout << "\nCant Reach Here  \n";
}

int main(int argc, char* argv[])
{
	TEA_Algorithm myTEA;
	union myMsgType myPlaintext, myCiphertext;
	unsigned long key[4] = {0xA0B0C0D0, 0xA1B1C1D1, 0xA2B2C2D2, 0xA3B3C3D3};

	strcpy(myPlaintext.text, "security");
	strcpy(myCiphertext.text, "unknown_");

	cout << "LAB1: Implementing the TEA symmetric encryption algorithm" << endl;
	cout << "__________________________________________________________" << endl << endl;

	cout << "Plaintext: " << myPlaintext.text << endl << endl;

	myTEA.Encrypt(key, myPlaintext.textConverted, myCiphertext.textConverted);

	cout << "Ciphertext: " << myCiphertext.text << " (" << myCiphertext.textConverted[0] << "," << myCiphertext.textConverted[1] << ")";
	cout << endl << endl;

	myTEA.Decrypt(key, myCiphertext.textConverted, myPlaintext.textConverted);
	cout << "Plaintext recovered: " << myPlaintext.text << endl << endl;
	cout << "__________________________________________________________" << endl;


	myTEA.CrackSymmetricKey(myPlaintext, myCiphertext);

	return 0;
}

شكرا مره أخرى Xacker ،

بالتوفيق .

http://informatic-ar.com منصة تعليمية عربية في علوم الحاسب والبرمجة

https://moalfat.com  للكتب الالكترونية والكورسات التعليمية

Everything we see now is just an engineering solution based on old science

#16

العفو،

وهذا كود الأسمبلي (قمت بتصحيح الجزء الذي تركته بخصوص ازدياد قيمة الرقم فوق حدود 0xFFFFFFFF)

.686
.model flat,stdcall
option casemap:none

include windows.inc
include kernel32.inc
include user32.inc
includelib user32.lib
includelib kernel32.lib

TEA_encode	PROTO	:DWORD,:DWORD,:DWORD

	  literal MACRO quoted_text:VARARG
		LOCAL local_text
		.data
		  local_text db quoted_text,0
		align 4
		.code
		EXITM <local_text>
	  ENDM
	  CTXT MACRO quoted_text:VARARG
		EXITM <offset literal(quoted_text)>
	  ENDM

.data
key				dd	4 dup (0)
cipher			dd	2 dup (0),0
myCipher		dd	2022673309,3810199360
nul				db	0; unused
buffer			db	10 dup (0),0
internal_key	dd	4 dup (0)
phase			db	0

.code
start:
xor		esi,esi
.while (esi <= 2147483648)
	mov		dword ptr [key],esi
	mov		dword ptr [key+4],esi
	mov		dword ptr [key+8],esi
	mov		dword ptr [key+12],esi
	invoke	TEA_encode,CTXT("security"),addr key,addr cipher
	invoke	lstrcmp,addr cipher,addr myCipher
	jne	@F
		invoke	wsprintf,addr buffer,CTXT("%lu"),esi
		invoke	MessageBox,NULL,addr buffer,CTXT("arabteam2000"),MB_OK
		mov		phase,1
		.break
@@:
	inc		esi
.endw
.if	(phase == 0)
	mov	esi,2147483649; low  dword
	xor	edi,edi		; high dword
					; EDI:ESI to represent values more than 0xFFFFFFFF
	.while (edi <= 1 && esi != 0) ; EDI ?= 0x00000001 & ESI ?= 0x00000000 < carry
		mov		dword ptr [key],esi
		mov		dword ptr [key+4],esi
		mov		dword ptr [key+8],esi
		mov		dword ptr [key+12],esi
		invoke	TEA_encode,CTXT("security"),addr key,addr cipher
		invoke	lstrcmp,addr cipher,addr myCipher
		jne	@F
			invoke	wsprintf,addr buffer,CTXT("%lu"),esi
			invoke	MessageBox,NULL,addr buffer,CTXT("arabteam2000"),MB_OK
			.break
	@@:
		add		esi,1
		adc		edi,0
	.endw
.endif
invoke	MessageBox,NULL,CTXT("i'm closing now"),CTXT("arabteam2000"),MB_OK
invoke	ExitProcess,NULL

TEA_encode	PROC	ptrData:DWORD,ptrKey:DWORD,ptrCipher:DWORD
;TEA algo by WiteG
	pushad
	mov	esi, ptrKey	
	mov	eax, dword ptr [esi]
	mov	ebx, dword ptr [esi+4]
	mov	ecx, dword ptr [esi+8]
	mov	edx, dword ptr [esi+12]	
	mov	dword ptr [internal_key], eax
	mov	dword ptr [internal_key+4], ebx
	mov	dword ptr [internal_key+8], ecx
	mov	dword ptr [internal_key+12], edx
	push	ebp
	mov	ebx, ptrData
	xor	edx, edx
	mov	esi, dword ptr [ebx]
	mov	edi, dword ptr [ebx+4]
	mov	ebp, 32
_loop:
	add	edx, 9E3779B9h
	mov	eax, edi
	mov	ecx, eax
	mov	ebx, edi
	shl	eax, 4
	shr	ebx, 5
	add	eax, dword ptr [internal_key+ 0*4]
	add	ebx, dword ptr [internal_key+ 1*4]
	add	ecx, edx
	xor	ecx, eax
	xor	ecx, ebx
	add	esi, ecx
	mov	eax, esi
	mov	ebx, esi
	mov	ecx, esi
	shl	eax, 4
	shr	ebx, 5
	add	eax, dword ptr [internal_key+ 2*4]
	add	ebx, dword ptr [internal_key+ 3*4]
	add	ecx, edx
	xor	ecx, eax
	xor	ecx, ebx
	add	edi, ecx
	dec	ebp
	jnz	_loop
	mov	dword ptr [internal_key], ebp
	mov	dword ptr [internal_key+4], ebp
	mov	dword ptr [internal_key+8], ebp
	mov	dword ptr [internal_key+12], ebp
	pop	ebp
	mov	ebx, ptrCipher
	mov	dword ptr [ebx], esi
	mov	dword ptr [ebx+4], edi
	popad
	ret
TEA_encode	ENDP
end start

تم تعديل هذه المشاركة بواسطة Xacker في 12 أكتوبر 2008 في 14:11

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

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