;加密程式 (encrypt.
asm)
include irvine32.inc
key=
239;1~
255之間的任何乙個值
bufmax=
128;緩衝區最大容量
.data
sprompt byte "enter a plain text:",0
sencrypt byte "cipher text :",0
sdecrypt byte "decrypted :",0
buffer byte bufmax+
1dup(0
) bufsize dword ?
.code
main proc
call inputthestring ;輸入明文
call translatebuffer ;加密緩衝區
mov edx,offset sencrypt ;顯示加密資訊
call displaymessage ;
call translatebuffer ;解密緩衝區
mov edx,offset sdecrypt ;
call displaymessage ;顯示解密資訊
call waitmsg ;
exit ;
main endp
;------
----
----
----
----
----
----
----
----
----
-- inputthestring proc
;;提示使用者輸入乙個純文字字串
;儲存字串和他的長度
;接受:無
;返回:無
;------
----
----
----
----
----
----
----
----
----
-- pushad ;儲存32位暫存器
mov edx,offset sprompt ;顯示提示
call writestring ;
mov ecx,bufmax ;字元計數器最大值
mov edx,offset buffer ;指向緩衝區
call readstring ;輸入字串
mov bufsize,eax ;儲存長度
call crlf
popad
retinputthestring endp
;------
----
----
----
----
----
----
----
----
----
-- displaymessage proc
;顯示加密或者解密資訊
;接受:edx指向訊息
;返回:無
;------
----
----
----
----
----
----
----
----
----
-- pushad
call writestring
mov edx,offset buffer ;顯示緩衝區
call writestring ;
call crlf ;
call crlf ;
popad ;
ret ;函式返回
displaymessage endp ;;--
----
----
----
----
----
----
----
----
----
----
-- translatebuffer proc
;;字串的每乙個位元組都與秘鑰位元組進行異或
;實現轉換
;接受:無
;返回:無
;------
----
----
----
----
----
----
----
----
-------
pushad
mov ecx,bufsize ;迴圈計數器
mov esi,0;
;緩衝區索引賦初值0
l1:xor buffer[esi]
,key ;轉換乙個字元
inc esi ;指向下乙個位元組
loop l1
popad
rettranslatebuffer endp
end main
陣列異或操作
給你兩個整數,n 和 start 陣列 nums 定義為 nums i start 2 i 下標從 0 開始 且 n nums.length 請返回 nums 中所有元素按位異或 xor 後得到的結果。示例 1 輸入 n 5,start 0 輸出 8 解釋 陣列 nums 為 0,2,4,6,8 其...
基於異或運算的對稱表
單鏈表只能方便的進行單向查詢,而雙鏈表可以方便的進行雙向查詢,但由於增加了乙個指標域,使得其儲存密度進一步降低。有一種方法 基於異或運算的對稱表 可以使用乙個指標域就能夠方便的進行雙向查詢,它是一種用時間換取空間的折中策略。異或運算回顧 3 5 6 011 101 110 x,y,x y x y x...
使用異或實現兩數交換
如果a b兩個值不相同,則異或結果為1。如果a b兩個值相同,異或結果為0。異或也叫半加運算,其運算法則相當於不帶進製的二進位制加法 二進位制下用1表示真,0表示假,則異或的運算法則為 0 0 0,1 0 1,0 1 1,1 1 0 同為0,異為1 這些法則與加法是相同的,只是不帶進製,所以異或常被...