new library: encryption algorithm DES

git-svn-id: svn://kolibrios.org@3321 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2013-03-04 12:02:07 +00:00
parent 31e9ec37f4
commit db7d8d421c
5 changed files with 1107 additions and 0 deletions

View File

@ -0,0 +1,8 @@
if not exist bin mkdir bin
@fasm.exe -m 16384 crypt_files.asm bin\crypt_files.kex
@kpack bin\crypt_files.kex
if not exist bin\toolbar.png @copy toolbar.png bin\toolbar.png
if not exist bin\font8x9.bmp @copy ..\..\..\..\fs\kfar\trunk\font8x9.bmp bin\font8x9.bmp
@fasm.exe -m 16384 ..\trunk\crypt_des.asm bin\crypt_des.obj
@kpack bin\crypt_des.obj
pause

View File

@ -0,0 +1,636 @@
use32
org 0x0
db 'MENUET01' ;¨¤¥­â¨ä. ¨á¯®«­ï¥¬®£® ä ©«  ¢á¥£¤  8 ¡ ©â
dd 0x1
dd start
dd i_end ;à §¬¥à ¯à¨«®¦¥­¨ï
dd mem
dd stacktop
dd 0
dd sys_path
include '../../../../macros.inc'
include '../../../../proc32.inc'
include '../../../../develop/libraries/box_lib/load_lib.mac'
include '../../../../develop/libraries/box_lib/trunk/box_lib.mac'
include '../../../../dll.inc'
@use_library_mem mem.Alloc,mem.Free,mem.ReAlloc,dll.Load
caption db '˜¨ä஢ ­¨¥  «£®à¨â¬®¬ DES 04.03.13',0 ;¯®¤¯¨áì ®ª­ 
struct FileInfoBlock
Function dd ?
Position dd ?
Flags dd ?
Count dd ?
Buffer dd ?
db ?
FileName dd ?
ends
run_file_70 FileInfoBlock
image_data dd 0 ;㪠§ â¥«ì ­  ¢à¥¬¥­­ãî ¯ ¬ïâì. ¤«ï ­ã¦¥­ ¯à¥®¡à §®¢ ­¨ï ¨§®¡à ¦¥­¨ï
fn_toolbar db 'toolbar.png',0
IMAGE_TOOLBAR_ICON_SIZE equ 16*16*3
IMAGE_TOOLBAR_SIZE equ IMAGE_TOOLBAR_ICON_SIZE*5
image_data_toolbar dd 0
IMAGE_FILE1_SIZE equ 128*144*3+54 ;à §¬¥à ä ©«  á ¨§®¡à ¦¥­¨¥¬
max_open_file_size equ 64*1024 ;64 Kb
macro load_image_file path,buf,size { ;¬ ªà®á ¤«ï § £à㧪¨ ¨§®¡à ¦¥­¨©
;path - ¬®¦¥â ¡ëâì ¯¥à¥¬¥­­®© ¨«¨ áâப®¢ë¬ ¯ à ¬¥â஬
if path eqtype '' ;¯à®¢¥à塞 § ¤ ­ «¨ áâப®© ¯ à ¬¥âà path
jmp @f
local .path_str
.path_str db path ;ä®à¬¨à㥬 «®ª «ì­ãî ¯¥à¥¬¥­­ãî
db 0
@@:
;32 - áâ ­¤ àâ­ë©  ¤à¥á ¯® ª®â®à®¬ã ¤®«¦¥­ ¡ëâì ¡ãä¥à á á¨á⥬­ë¬ ¯ã⥬
copy_path .path_str,[32],file_name,0x0
else
copy_path path,[32],file_name,0x0 ;ä®à¬¨à㥬 ¯®«­ë© ¯ãâì ª ä ©«ã ¨§®¡à ¦¥­¨ï, ¯®¤à §ã¬¥¢ ¥¬ çâ® ®­ ¢ ®¤­®© ¯ ¯ª¥ á ¯à®£à ¬¬®©
end if
stdcall mem.Alloc, dword size ;¢ë¤¥«ï¥¬ ¯ ¬ïâì ¤«ï ¨§®¡à ¦¥­¨ï
mov [buf],eax
mov eax,70 ;70-ï äã­ªæ¨ï à ¡®â  á ä ©« ¬¨
mov [run_file_70.Function], 0
mov [run_file_70.Position], 0
mov [run_file_70.Flags], 0
mov [run_file_70.Count], dword size
m2m [run_file_70.Buffer], [buf]
mov byte[run_file_70+20], 0
mov [run_file_70.FileName], file_name
mov ebx,run_file_70
int 0x40 ;§ £à㦠¥¬ ä ©« ¨§®¡à ¦¥­¨ï
cmp ebx,0xffffffff
je @f
;®¯à¥¤¥«ï¥¬ ¢¨¤ ¨§®¡à ¦¥­¨ï ¨ ¯¥à¥¢®¤¨¬ ¥£® ¢® ¢à¥¬¥­­ë© ¡ãä¥à image_data
stdcall dword[img_decode], dword[buf],ebx,0
mov dword[image_data],eax
;¯à¥®¡à §ã¥¬ ¨§®¡à ¦¥­¨¥ ª ä®à¬ âã rgb
stdcall dword[img_to_rgb2], dword[image_data],dword[buf]
;㤠«ï¥¬ ¢à¥¬¥­­ë© ¡ãä¥à image_data
stdcall dword[img_destroy], dword[image_data]
@@:
}
align 4
start:
load_libraries l_libs_start,l_libs_end
;¯à®¢¥àª  ­  ᪮«ìª® 㤠筮 § £ã§¨« áì ¡¨¡«¨®â¥ª 
mov ebp,lib_0
cmp dword [ebp+ll_struc_size-4],0
jz @f
mcall -1 ;exit not correct
@@:
mcall 48,3,sc,sizeof.system_colors
mcall 40,0xC0000027
stdcall [OpenDialog_Init],OpenDialog_data ;¯®¤£®â®¢ª  ¤¨ «®£ 
stdcall [buf2d_create], buf_0 ;ᮧ¤ ­¨¥ ¡ãä¥à 
load_image_file 'font8x9.bmp', image_data_toolbar,IMAGE_FILE1_SIZE
stdcall [buf2d_create_f_img], buf_1,[image_data_toolbar] ;ᮧ¤ ¥¬ ¡ãä¥à
stdcall mem.Free,[image_data_toolbar] ;®á¢®¡®¦¤ ¥¬ ¯ ¬ïâì
stdcall [buf2d_conv_24_to_8], buf_1,1 ;¤¥« ¥¬ ¡ãä¥à ¯à®§à ç­®á⨠8 ¡¨â
stdcall [buf2d_convert_text_matrix], buf_1
load_image_file fn_toolbar, image_data_toolbar,IMAGE_TOOLBAR_SIZE
stdcall mem.Alloc,max_open_file_size
mov dword[open_file],eax
call but_new_file
align 4
red_win:
call draw_window
align 4
still:
mcall 10
cmp al,1
jz red_win
cmp al,2
jz key
cmp al,3
jz button
cmp al,6 ;¬ëèì
jne @f
jmp mouse
@@:
jmp still
align 4
draw_window:
pushad
mcall 12,1
; *** à¨á®¢ ­¨¥ £« ¢­®£® ®ª­  (¢ë¯®«­ï¥âáï 1 à § ¯à¨ § ¯ã᪥) ***
xor eax,eax
mov ebx,(20 shl 16)+485
mov ecx,(20 shl 16)+415
mov edx,[sc.work]
or edx,(3 shl 24)+0x10000000+0x20000000
mov edi,caption
int 0x40
; *** ᮧ¤ ­¨¥ ª­®¯®ª ­  ¯ ­¥«ì ***
mov eax,8
mov ebx,(5 shl 16)+20
mov ecx,(5 shl 16)+20
mov edx,3
mov esi,[sc.work_button]
int 0x40
mov ebx,(30 shl 16)+20
mov edx,4
int 0x40
mov ebx,(55 shl 16)+20
mov edx,5
int 0x40
mov ebx,(85 shl 16)+20
mov edx,6
int 0x40
mov ebx,(110 shl 16)+20
mov edx,7
int 0x40
; *** à¨á®¢ ­¨¥ ¨ª®­®ª ­  ª­®¯ª å ***
mov eax,7
mov ebx,[image_data_toolbar]
mov ecx,(16 shl 16)+16
mov edx,(7 shl 16)+7 ;icon new
int 0x40
add ebx,IMAGE_TOOLBAR_ICON_SIZE
add edx,(25 shl 16) ;icon open
int 0x40
add ebx,IMAGE_TOOLBAR_ICON_SIZE
add edx,(25 shl 16) ;icon save
int 0x40
add ebx,IMAGE_TOOLBAR_ICON_SIZE
add edx,(30 shl 16) ;
int 0x40
add ebx,IMAGE_TOOLBAR_ICON_SIZE
add edx,(25 shl 16) ;
int 0x40
stdcall [edit_box_draw], edit1
; *** à¨á®¢ ­¨¥ ¡ãä¥à  ***
stdcall [buf2d_draw], buf_0
mcall 12,2
popad
ret
align 4
key:
mcall 2
stdcall [edit_box_key], dword edit1
jmp still
align 4
mouse:
stdcall [edit_box_mouse], edit1
jmp still
align 4
button:
mcall 17
cmp ah,3
jne @f
call but_new_file
@@:
cmp ah,4
jne @f
call but_open_file
@@:
cmp ah,5
jne @f
call but_save_file
@@:
cmp ah,6
jne @f
call but_1
@@:
cmp ah,7
jne @f
call but_2
@@:
cmp ah,1
jne still
.exit:
stdcall [buf2d_delete],buf_0
stdcall [buf2d_delete],buf_1 ;㤠«ï¥¬ ¡ãä¥à
stdcall mem.Free,[image_data_toolbar]
stdcall mem.Free,[open_file]
mcall -1
align 4
but_new_file:
mov dword[open_file_size],0
call draw_file
ret
align 4
open_file dd 0 ;㪠§ â¥«ì ­  ¯ ¬ïâì ¤«ï ®âªàëâ¨ï ä ©«®¢
open_file_size dd 0 ;à §¬¥à ®âªàë⮣® ä ©«  (¤®«¦¥­ ¡ëâì ­¥ ¡®«ìè¥ max_open_file_size)
align 4
but_open_file:
pushad
copy_path open_dialog_name,communication_area_default_path,file_name,0
mov [OpenDialog_data.type],0
stdcall [OpenDialog_Start],OpenDialog_data
cmp [OpenDialog_data.status],2
je .end_open_file
;ª®¤ ¯à¨ 㤠筮¬ ®âªàë⨨ ¤¨ «®£ 
mov eax,70 ;70-ï äã­ªæ¨ï à ¡®â  á ä ©« ¬¨
mov [run_file_70.Function], 0
mov [run_file_70.Position], 0
mov [run_file_70.Flags], 0
mov dword[run_file_70.Count], max_open_file_size
m2m [run_file_70.Buffer], [open_file]
mov byte[run_file_70+20], 0
mov dword[run_file_70.FileName], openfile_path
mov ebx,run_file_70
int 0x40 ;§ £à㦠¥¬ ä ©« ¨§®¡à ¦¥­¨ï
cmp ebx,0xffffffff
je .end_open_file
mov [open_file_size],ebx
add ebx,open_file
mov byte[ebx],0 ;­  á«ãç © ¥á«¨ à ­¥¥ ¡ë« ®âªàëâ ä ©« ¡®«ì襣® à §¬¥à  ç¨á⨬ ª®­¥æ ¡ãä¥à  á ä ©«®¬
mcall 71,1,openfile_path
call draw_file
.end_open_file:
popad
ret
align 4
draw_file:
pushad
stdcall [buf2d_clear], buf_0, [buf_0.color]
cmp dword[open_file_size],0
je .open_file
mov eax,[open_file]
mov ebx,3
mov edx,dword[open_file_size]
.cycle_0:
mov edi,txt_buf
mov esi,eax
mov ecx,56
;cld
rep movsb
mov byte[edi],0
mov edi,txt_buf
mov ecx,56
.cycle_1:
cmp byte[edi],0
je @f
cmp byte[edi],13
je @f
jmp .ok
@@:
mov byte[edi],' ' ;­¥¯¥ç â­ë¥ ᨬ¢®«ë § ¬¥­ï¥¬ ­  ¯à®¡¥«
.ok:
inc edi
loop .cycle_1
stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,4,ebx,0xb0
sub edx,56
cmp edx,1
jl @f
add eax,56
add ebx,10
cmp ebx,dword[buf_0.h]
jl .cycle_0
jmp @f
.open_file:
stdcall [buf2d_draw_text], buf_0, buf_1,txt_openfile,3,3,0xb000
@@:
stdcall [buf2d_draw], buf_0
popad
ret
align 4
but_save_file:
pushad
copy_path open_dialog_name,communication_area_default_path,file_name,0
mov [OpenDialog_data.type],1
stdcall [OpenDialog_Start],OpenDialog_data
cmp [OpenDialog_data.status],2
je .end_save_file
;ª®¤ ¯à¨ 㤠筮¬ ®âªàë⨨ ¤¨ «®£ 
mov eax,70 ;70-ï äã­ªæ¨ï à ¡®â  á ä ©« ¬¨
mov [run_file_70.Function], 2
mov [run_file_70.Position], 0
mov [run_file_70.Flags], 0
mov ebx, dword[open_file]
mov [run_file_70.Buffer], ebx
mov ebx,[open_file_size]
mov dword[run_file_70.Count], ebx ;à §¬¥à ä ©« 
mov byte[run_file_70+20], 0
mov dword[run_file_70.FileName], openfile_path
mov ebx,run_file_70
int 0x40 ;á®å࠭塞 ä ©« ¨§®¡à ¦¥­¨ï
;cmp ebx,0xffffffff
;je .end_save_file
; ... á®®¡é¥­¨¥ ® ­¥ã¤ ç­®¬ á®åà ­¥­¨¨ ...
.end_save_file:
popad
ret
align 4
but_1:
push eax
mov eax,[open_file_size]
shr eax,3
stdcall [des_encryption], txt_key,mem_key,[open_file],eax
pop eax
call draw_file
ret
align 4
but_2:
push eax
mov eax,[open_file_size]
shr eax,3
stdcall [des_decryption], txt_key,mem_key,[open_file],eax
pop eax
call draw_file
ret
;¤ ­­ë¥ ¤«ï ¤¨ «®£  ®âªàëâ¨ï ä ©«®¢
align 4
OpenDialog_data:
.type dd 0 ;0 - ®âªàëâì, 1 - á®åà ­¨âì, 2 - ¢ë¡à âì ¤â४â®à¨î
.procinfo dd procinfo ;+4
.com_area_name dd communication_area_name ;+8
.com_area dd 0 ;+12
.opendir_path dd plugin_path ;+16
.dir_default_path dd default_dir ;+20
.start_path dd file_name ;+24 ¯ãâì ª ¤¨ «®£ã ®âªàëâ¨ï ä ©«®¢
.draw_window dd draw_window ;+28
.status dd 0 ;+32
.openfile_path dd openfile_path ;+36 ¯ãâì ª ®âªà뢠¥¬®¬ã ä ©«ã
.filename_area dd filename_area ;+40
.filter_area dd Filter
.x:
.x_size dw 420 ;+48 ; Window X size
.x_start dw 10 ;+50 ; Window X position
.y:
.y_size dw 320 ;+52 ; Window y size
.y_start dw 10 ;+54 ; Window Y position
default_dir db '/rd/1',0
communication_area_name:
db 'FFFFFFFF_open_dialog',0
open_dialog_name:
db 'opendial',0
communication_area_default_path:
db '/rd/1/File managers/',0
Filter:
dd Filter.end - Filter ;.1
.1:
db 'TXT',0
db 'ASM',0
.end:
db 0
head_f_i:
head_f_l db '‘¨á⥬­ ï ®è¨¡ª ',0
system_dir_0 db '/sys/lib/'
lib_name_0 db 'proc_lib.obj',0
err_message_found_lib_0 db '<27>¥ ­ ©¤¥­  ¡¨¡«¨®â¥ª  ',39,'proc_lib.obj',39,0
err_message_import_0 db 'Žè¨¡ª  ¯à¨ ¨¬¯®à⥠¡¨¡«¨®â¥ª¨ ',39,'proc_lib.obj',39,0
system_dir_1 db '/sys/lib/'
lib_name_1 db 'libimg.obj',0
err_message_found_lib_1 db '<27>¥ ­ ©¤¥­  ¡¨¡«¨®â¥ª  ',39,'libimg.obj',39,0
err_message_import_1 db 'Žè¨¡ª  ¯à¨ ¨¬¯®à⥠¡¨¡«¨®â¥ª¨ ',39,'libimg.obj',39,0
system_dir_2 db '/sys/lib/'
lib_name_2 db 'buf2d.obj',0
err_msg_found_lib_2 db '<27>¥ ­ ©¤¥­  ¡¨¡«¨®â¥ª  ',39,'buf2d.obj',39,0
err_msg_import_2 db 'Žè¨¡ª  ¯à¨ ¨¬¯®à⥠¡¨¡«¨®â¥ª¨ ',39,'buf2d',39,0
system_dir_3 db '/sys/lib/'
lib_name_3 db 'crypt_des.obj',0
err_msg_found_lib_3 db '<27>¥ ­ ©¤¥­  ¡¨¡«¨®â¥ª  ',39,'crypt_des.obj',39,0
err_msg_import_3 db 'Žè¨¡ª  ¯à¨ ¨¬¯®à⥠¡¨¡«¨®â¥ª¨ ',39,'crypt_des',39,0
system_dir_4 db '/sys/lib/'
lib_name_4 db 'box_lib.obj',0
err_msg_found_lib_4 db '<27>¥ ­ ©¤¥­  ¡¨¡«¨®â¥ª  ',39,'box_lib.obj',39,0
err_msg_import_4 db 'Žè¨¡ª  ¯à¨ ¨¬¯®à⥠¡¨¡«¨®â¥ª¨ ',39,'box_lib',39,0
l_libs_start:
lib_0 l_libs lib_name_0, sys_path, file_name, system_dir_0,\
err_message_found_lib_0, head_f_l, proclib_import,err_message_import_0, head_f_i
lib_1 l_libs lib_name_1, sys_path, file_name, system_dir_1,\
err_message_found_lib_1, head_f_l, import_libimg, err_message_import_1, head_f_i
lib_2 l_libs lib_name_2, sys_path, library_path, system_dir_2,\
err_msg_found_lib_2,head_f_l,import_buf2d,err_msg_import_2,head_f_i
lib_3 l_libs lib_name_3, sys_path, library_path, system_dir_3,\
err_msg_found_lib_3,head_f_l,import_des,err_msg_import_3,head_f_i
lib_4 l_libs lib_name_4, sys_path, library_path, system_dir_4,\
err_msg_found_lib_4,head_f_l,import_box_lib,err_msg_import_4,head_f_i
l_libs_end:
align 4
import_libimg:
dd alib_init1
img_is_img dd aimg_is_img
img_info dd aimg_info
img_from_file dd aimg_from_file
img_to_file dd aimg_to_file
img_from_rgb dd aimg_from_rgb
img_to_rgb dd aimg_to_rgb
img_to_rgb2 dd aimg_to_rgb2
img_decode dd aimg_decode
img_encode dd aimg_encode
img_create dd aimg_create
img_destroy dd aimg_destroy
img_destroy_layer dd aimg_destroy_layer
img_count dd aimg_count
img_lock_bits dd aimg_lock_bits
img_unlock_bits dd aimg_unlock_bits
img_flip dd aimg_flip
img_flip_layer dd aimg_flip_layer
img_rotate dd aimg_rotate
img_rotate_layer dd aimg_rotate_layer
img_draw dd aimg_draw
dd 0,0
alib_init1 db 'lib_init',0
aimg_is_img db 'img_is_img',0 ;®¯à¥¤¥«ï¥â ¯® ¤ ­­ë¬, ¬®¦¥â «¨ ¡¨¡«¨®â¥ª  ᤥ« âì ¨§ ­¨å ¨§®¡à ¦¥­¨¥
aimg_info db 'img_info',0
aimg_from_file db 'img_from_file',0
aimg_to_file db 'img_to_file',0
aimg_from_rgb db 'img_from_rgb',0
aimg_to_rgb db 'img_to_rgb',0 ;¯à¥®¡à §®¢ ­¨¥ ¨§®¡à ¦¥­¨ï ¢ ¤ ­­ë¥ RGB
aimg_to_rgb2 db 'img_to_rgb2',0
aimg_decode db 'img_decode',0 ; ¢â®¬ â¨ç¥áª¨ ®¯à¥¤¥«ï¥â ä®à¬ â £à ä¨ç¥áª¨å ¤ ­­ëå
aimg_encode db 'img_encode',0
aimg_create db 'img_create',0
aimg_destroy db 'img_destroy',0
aimg_destroy_layer db 'img_destroy_layer',0
aimg_count db 'img_count',0
aimg_lock_bits db 'img_lock_bits',0
aimg_unlock_bits db 'img_unlock_bits',0
aimg_flip db 'img_flip',0
aimg_flip_layer db 'img_flip_layer',0
aimg_rotate db 'img_rotate',0
aimg_rotate_layer db 'img_rotate_layer',0
aimg_draw db 'img_draw',0
align 4
proclib_import: ;®¯¨á ­¨¥ íªá¯®àâ¨à㥬ëå ä㭪権
OpenDialog_Init dd aOpenDialog_Init
OpenDialog_Start dd aOpenDialog_Start
dd 0,0
aOpenDialog_Init db 'OpenDialog_init',0
aOpenDialog_Start db 'OpenDialog_start',0
align 4
import_buf2d:
init dd sz_init
buf2d_create dd sz_buf2d_create
buf2d_create_f_img dd sz_buf2d_create_f_img
buf2d_clear dd sz_buf2d_clear
buf2d_draw dd sz_buf2d_draw
buf2d_delete dd sz_buf2d_delete
;buf2d_line dd sz_buf2d_line
;buf2d_rect_by_size dd sz_buf2d_rect_by_size
;buf2d_filled_rect_by_size dd sz_buf2d_filled_rect_by_size
;buf2d_circle dd sz_buf2d_circle
;buf2d_img_hdiv2 dd sz_buf2d_img_hdiv2
;buf2d_img_wdiv2 dd sz_buf2d_img_wdiv2
buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8
;buf2d_conv_24_to_32 dd sz_buf2d_conv_24_to_32
;buf2d_bit_blt dd sz_buf2d_bit_blt
;buf2d_bit_blt_transp dd sz_buf2d_bit_blt_transp
;buf2d_bit_blt_alpha dd sz_buf2d_bit_blt_alpha
;buf2d_curve_bezier dd sz_buf2d_curve_bezier
buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix
buf2d_draw_text dd sz_buf2d_draw_text
;buf2d_crop_color dd sz_buf2d_crop_color
;buf2d_offset_h dd sz_buf2d_offset_h
;buf2d_flood_fill dd sz_buf2d_flood_fill
;buf2d_set_pixel dd sz_buf2d_set_pixel
dd 0,0
sz_init db 'lib_init',0
sz_buf2d_create db 'buf2d_create',0
sz_buf2d_create_f_img db 'buf2d_create_f_img',0
sz_buf2d_clear db 'buf2d_clear',0
sz_buf2d_draw db 'buf2d_draw',0
sz_buf2d_delete db 'buf2d_delete',0
;sz_buf2d_line db 'buf2d_line',0
;sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0
;sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0
;sz_buf2d_circle db 'buf2d_circle',0
;sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0
;sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0
sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0
;sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0
;sz_buf2d_bit_blt db 'buf2d_bit_blt',0
;sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0
;sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0
;sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0
sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0
sz_buf2d_draw_text db 'buf2d_draw_text',0
;sz_buf2d_crop_color db 'buf2d_crop_color',0
;sz_buf2d_offset_h db 'buf2d_offset_h',0
;sz_buf2d_flood_fill db 'buf2d_flood_fill',0
;sz_buf2d_set_pixel db 'buf2d_set_pixel',0
align 4
import_des: ;®¯¨á ­¨¥ íªá¯®àâ¨à㥬ëå ä㭪権
des_encryption dd sz_des_encryption
des_decryption dd sz_des_decryption
dd 0,0
sz_des_encryption db 'des_encryption',0
sz_des_decryption db 'des_decryption',0
align 4
import_box_lib:
;dd sz_init1
edit_box_draw dd sz_edit_box_draw
edit_box_key dd sz_edit_box_key
edit_box_mouse dd sz_edit_box_mouse
;edit_box_set_text dd sz_edit_box_set_text
dd 0,0
;sz_init1 db 'lib_init',0
sz_edit_box_draw db 'edit_box',0
sz_edit_box_key db 'edit_box_key',0
sz_edit_box_mouse db 'edit_box_mouse',0
;sz_edit_box_set_text db 'edit_box_set_text',0
mouse_dd dd 0x0
sc system_colors
align 16
procinfo process_information
align 4
buf_0: dd 0 ;㪠§ â¥«ì ­  ¡ãä¥à ¨§®¡à ¦¥­¨ï
dw 5 ;+4 left
dw 31 ;+6 top
.w: dd 460 ;+8 w
.h: dd 350 ;+12 h
.color: dd 0xffffd0 ;+16 color
db 24 ;+20 bit in pixel
align 4
buf_1:
dd 0 ;㪠§ â¥«ì ­  ¡ãä¥à ¨§®¡à ¦¥­¨ï
dw 25 ;+4 left
dw 25 ;+6 top
dd 128 ;+8 w
dd 144 ;+12 h
dd 0 ;+16 color
db 24 ;+20 bit in pixel
edit1 edit_box 58, 140,8, 0xffffff, 0xff, 0x80ff, 0, 0x8000, 8, txt_key, mouse_dd, ed_focus+ed_always_focus,8,8
txt_openfile db 'Žâªà®©â¥ ä ©« ¤«ï è¨ä஢ ­¨ï ¨«¨ ¤¥è¨ä஢ ­¨ï.',0
txt_buf rb 80
txt_key db 'des_0123',0
mem_key rb 120
i_end:
rb 2048
stacktop:
sys_path rb 1024
file_name:
rb 1024 ;4096
library_path rb 1024
plugin_path rb 4096
openfile_path rb 4096
filename_area rb 256
mem:

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -0,0 +1,460 @@
;
; áèáëèîòåêà äëÿ øèôðîâàíèÿ ïî àëãîðèòìó DES
;
format MS COFF
public EXPORTS
section '.flat' code readable align 16
include '../../../../macros.inc'
include '../../../../proc32.inc'
;description:
; ôóíêöèÿ øèôðîâàíèÿ ôàéëîâ
;input:
; key - âõîäíîé êëþ÷ 64 áèò
; mem_keys - ïàìÿòü äëÿ ôîðìèðîâàíèÿ êëþ÷åé (ðàçìåð 120 áàéò)
; block - óêàçàòåëü íà ïåðâûé øèôðóåìûé 8 áàéòíûé áëîê
; b_count - ÷èñëî áëîêîâ äëÿ øèôðîâàíèÿ
align 4
proc des_encryption, key:dword, mem_keys:dword, block:dword, b_count:dword
locals
n dd ? ;ïåðåìåííàÿ öèêëà
endl
pushad
stdcall encryption_key, [key],[mem_keys]
;íà÷àëüíàÿ ïåðåñòàíîâêà ip
mov ecx,[b_count]
cmp ecx,1
jl .end_funct
mov edi,[block]
cld
@@:
mov esi,[mem_keys]
add esi,112
stdcall fun_convert_bits, edi, esi, oper_ip, 64
movsd
movsd
loop @b
mov ecx,[b_count]
mov esi,[block]
;cld
.cycle_3:
mov dword[n],0
.funct_f:
mov edi,[mem_keys]
add edi,112
;ïåðåñòàâëÿåì áëîê R0(32) ïî ìàòðèöå e
stdcall fun_convert_bits, esi, edi, oper_e, 48
;edi - R0~e (48 áèò)
;esi - L0R0 (64 áèòà)
stdcall fun_r0xorki_si, edi,[mem_keys],[n]
;edi - (R0~e xor ki)~Si (32 áèòà)
;ïåðåñòàíîâêà p
mov eax,edi
add eax,4
stdcall fun_convert_bits, edi, eax, oper_p, 32
;ïèøåì R0 â L0, è (L0 xor (R0~e xor ki)~Si) â R0
mov edx,dword[esi+4]
mov ebx,dword[esi]
xor edx,dword[eax]
mov dword[esi],edx
mov dword[esi+4],ebx
inc dword[n]
cmp dword[n],16
jl .funct_f
add esi,8 ;ïåðåõîä íà ñëåäóþùèé 64 áèòíûé øèôðóåìûé áëîê
loop .cycle_3
;êîíå÷íàÿ ïåðåñòàíîâêà ip_inv
mov ecx,[b_count]
mov edi,[block]
;cld
@@:
mov esi,[mem_keys]
add esi,112
stdcall fun_convert_bits, edi, esi, oper_ip_inv, 64
movsd
movsd
loop @b
.end_funct:
popad
ret
endp
;description:
; ôóíêöèÿ ðàñøèôðîâàíèÿ ôàéëîâ
;input:
; key - âõîäíîé êëþ÷ 64 áèò
; mem_keys - ïàìÿòü äëÿ ôîðìèðîâàíèÿ êëþ÷åé (ðàçìåð 120 áàéò)
; block - óêàçàòåëü íà ïåðâûé ðàñøèôðîâûâàåìûé 8 áàéòíûé áëîê
; b_count - ÷èñëî áëîêîâ äëÿ ðàñøèôðîâàíèÿ
align 4
proc des_decryption, key:dword, mem_keys:dword, block:dword, b_count:dword
locals
n dd ? ;ïåðåìåííàÿ öèêëà
endl
pushad
stdcall encryption_key, [key],[mem_keys]
;íà÷àëüíàÿ ïåðåñòàíîâêà ip
mov ecx,[b_count]
cmp ecx,1
jl .end_funct
mov edi,[block]
cld
@@:
mov esi,[mem_keys]
add esi,112
stdcall fun_convert_bits, edi, esi, oper_ip, 64
movsd
movsd
loop @b
mov ecx,[b_count]
mov esi,[block]
;cld
.cycle_3:
mov dword[n],16
.funct_f:
dec dword[n]
mov edi,[mem_keys]
add edi,112
;ïåðåñòàâëÿåì áëîê L0(32) ïî ìàòðèöå e
add esi,4
stdcall fun_convert_bits, esi, edi, oper_e, 48
sub esi,4
;edi - L0~e (48 áèò)
;esi - L0R0 (64 áèòà)
stdcall fun_r0xorki_si, edi,[mem_keys],[n]
;edi - (L0~e xor ki)~Si (32 áèòà)
;ïåðåñòàíîâêà p
mov eax,edi
add eax,4
stdcall fun_convert_bits, edi, eax, oper_p, 32
;ïèøåì L0 â R0, è (R0 xor (L0~e xor ki)~Si) â L0
mov edx,dword[esi]
mov ebx,dword[esi+4]
xor edx,dword[eax]
mov dword[esi+4],edx
mov dword[esi],ebx
cmp dword[n],0
jg .funct_f
add esi,8 ;ïåðåõîä íà ñëåäóþùèé 64 áèòíûé øèôðóåìûé áëîê
loop .cycle_3
;êîíå÷íàÿ ïåðåñòàíîâêà ip_inv
mov ecx,[b_count]
mov edi,[block]
;cld
@@:
mov esi,[mem_keys]
add esi,112
stdcall fun_convert_bits, edi, esi, oper_ip_inv, 64
movsd
movsd
loop @b
.end_funct:
popad
ret
endp
;description:
; ïåðåñòàíîâêà áèòîâ ïî óêàùàííîé ìàòðèöå
;input:
; m_inp - ïàìÿòü ñ èñõîäíûìè äàííûìè
; m_out - ïàìÿòü äëÿ ïðåîáðàçîâàííûõ äàííûõ
; c_tbl - òàáëèöà äëÿ ïåðåñòàíîâêè
; tbl_s - ðàçìåð òàáëèöû äëÿ ïåðåñòàíîâêè
align 4
proc fun_convert_bits, m_inp:dword, m_out:dword, c_tbl:dword, tbl_s:dword
pushad
mov esi,[m_inp]
mov edi,[m_out]
mov eax,[c_tbl]
mov ecx,[tbl_s]
xor edx,edx
mov dword[edi],edx
cmp ecx,32
jle @f
mov dword[edi+4],edx
@@:
inc edx
cld
.cycle_0:
movzx ebx,byte[eax]
btr ebx,5
jc .tbl_h
bt dword[esi],ebx
jnc @f
or dword[edi],edx
@@:
jmp @f
.tbl_h:
bt dword[esi+4],ebx
jnc @f
or dword[edi],edx
@@:
rol edx,1
jnc @f
add edi,4
@@:
inc eax
loop .cycle_0
popad
ret
endp
;description:
; ñëîæåíèå R0(48) xor Ki(48) è 8 ïðåîáðàçîâàíèé ïî Si
;intput:
; data_r0 - R0 (48 áèò)
; data_key - óêàçàòåëü íà ìàññèâ êëþ÷åé (ïî 48 áèò)
; n - íîìåð êëþ÷à â ìàññèâå
;output:
; data_r0 - (R0 xor Ki)~Si (32 áèòà)
align 4
proc fun_r0xorki_si, data_r0:dword, data_key:dword, n:dword
pushad
mov edi,[data_r0]
mov eax,[n]
imul eax,7 ;56 áèò - ðàññòîÿíèå ìåæäó êëþ÷àìè (ñàìè êëþ÷è 48 áèò)
add eax,[data_key]
mov ebx,dword[eax]
xor dword[edi],ebx
mov ebx,dword[eax+4] ;mov bx,word[eax+4]
xor dword[edi+4],ebx ;xor word[edi+4],bx
;edi - óêàçàòåëü íà çíà÷åíèå R0 xor Ki
mov eax,dword[edi]
mov ebx,dword[edi+4]
;bx:eax - 48 áèò çíà÷åíèå R0 xor Ki
lea esi,[oper_s] ;âûáèðàåì òàáëèöó S0
mov ecx,8
.cycle_0:
mov dl,al
and edx,31
shr dl,1
jnc @f
bts edx,4
@@:
bt eax,5
jnc @f
bts edx,5
@@:
add edx,esi
mov dl,byte[edx] ;dl - 4 áèòíîå çíà÷åíèå ïîëó÷åííîå èç Si
bt ecx,0
jc @f
;1) ecx - ÷åòíûé
mov byte[edi],dl
jmp .next
@@:
;2) ecx - íå ÷åòíûé
shl dl,4
or byte[edi],dl
inc edi
.next:
shr eax,6
ror ebx,6
mov edx,ebx
and edx,0xfc000000
or eax,edx
;èëè 6 ðàç: shr ebx,1 rcr eax,1
add esi,64 ;ïåðåõîäèì íà ñëåäóþùóþ òàáëèöó Si
loop .cycle_0
popad
ret
endp
;description:
; ïðîöåäóðà ôîðìèðîâàíèÿ êëþ÷åé äëÿ øèôðîâàíèÿ
;intput:
; key - âõîäíîé êëþ÷ 64 áèò
; key_b - 16 ïðåîáðàçîâàííûõ êëþ÷åé ïî 48 áèò
; ðàçìåð ïàìÿòè key_b äîëæåí áûòü íå ìåíüøå 120 áàéò
align 4
proc encryption_key, key:dword, key_b:dword
pushad
mov esi,[key]
mov edi,[key_b]
;ïåðåñòàâëÿåì âõîäíîé êëþ÷ ïî ìàòðèöå
stdcall fun_convert_bits, esi, edi, oper_b, 56
;â ebx íàõîäèì C0
mov ebx,dword[edi]
and ebx,0xfffffff
;â edx íàõîäèì D0
mov edx,dword[edi+3]
shr edx,4
;íàõîäèì 16 ïîäêëþ÷åé, äëèííîé ïî 56 áèò
;;;mov edi,[key_b]
lea esi,[oper_r]
.cycle_1:
mov cl,byte[esi]
cmp cl,0
je .cycle_end
shl ebx,cl
btr ebx,28
jnc @f
or ebx,1
@@:
btr ebx,29
jnc @f
or ebx,2
@@:
shl edx,cl
btr edx,28
jnc @f
or edx,1
@@:
btr edx,29
jnc @f
or edx,2
@@:
mov dword[edi+3],0
mov dword[edi],ebx
shl edx,4
or dword[edi+3],edx
add edi,7
shr edx,4
inc esi
jmp .cycle_1
.cycle_end:
;ñæàòèå êëþ÷åé ñ 56 äî 48 áèò
mov edi,[key_b]
mov esi,edi
add esi,112 ;112 - àäðåñ çà ïðåäåëàìè 16*7
mov ecx,16
cld
@@:
stdcall fun_convert_bits, edi, esi, oper_c, 48
movsd
movsw
mov byte[edi],0 ;îáðåçàåì 7-é áàéò
inc edi
sub esi,6
loop @b
popad
ret
endp
align 4
oper_ip db 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,\
56,48,40,32,24,16, 8, 0,58,50,42,34,26,18,10, 2,\
60,52,44,36,28,20,12, 4,62,54,46,38,30,22,14, 6
align 4
oper_ip_inv db 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,32, 0,40, 8,48,16,56,24
align 4
oper_e db 31,0,1,2,3,4,\
3, 4, 5, 6, 7, 8,\
7, 8, 9,10,11,12,\
11,12,13,14,15,16,\
15,16,17,18,19,20,\
19,20,21,22,23,24,\
23,24,25,26,27,28,\
27,28,29,30,31, 0
align 4
oper_b db 56,48,40,32,24,16,8,\
0,57,49,41,33,25,17,\
9, 1,58,50,42,34,26,\
18,10, 2,59,51,43,35,\
62,54,46,38,30,22,14,\
6,61,53,45,37,29,21,\
13, 5,60,52,44,36,28,\
20,12, 4,27,19,11, 3
oper_r db 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1,0
align 4
oper_c db 13,16,10,23,0,4,\
2,27,14, 5,20, 9,\
22,18,11, 3,25, 7,\
15, 6,26,19,12, 1,\
40,51,30,36,46,54,\
29,39,50,44,32,47,\
43,48,38,55,33,52,\
45,41,49,35,28,31
align 4
oper_s db 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,\
13, 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,14,\
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,3,5,8,\
2, 1,14, 7, 4,10,8,13,15,12,9,0,3,5,6,11
align 4
oper_p db 15,6,19,20,28,11,27,16,\
0,14,22,25, 4,17,30, 9,\
1, 7,23,13,31,26, 2, 8,\
18,12,29, 5,21,10, 3,24
align 16
EXPORTS:
dd sz_des_encryption, des_encryption
dd sz_des_decryption, des_decryption
dd 0,0
sz_des_encryption db 'des_encryption',0
sz_des_decryption db 'des_decryption',0

View File

@ -0,0 +1,3 @@
@fasm.exe -m 16384 crypt_des.asm crypt_des.obj
@kpack crypt_des.obj
pause