Advertisement
sufokmpc

YENC ENCODER

Dec 20th, 2011
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; --------------
  2. ; YENC ENCODER
  3. ; x0rc1zt
  4. ; v1.0
  5. ; jully 2011
  6. ; --------------
  7.  
  8. #Sourcefilebuff = 0
  9. #Destfilebuff = 1
  10.  
  11. If OpenConsole()
  12.  
  13.   PrintN("* yEnc Encoder")
  14.   PrintN("* Version 1.0")
  15.   PrintN("* x0rc1zt")
  16.   PrintN("")
  17.  
  18.   Print("Enter the file name: ")
  19.  
  20.   sourcefile$ = Input()
  21.   sourcefilesize.q = FileSize(sourcefile$)
  22.  
  23.   If ReadFile(#Sourcefilebuff, sourcefile$) ; Open the source file
  24.    
  25.     destfile$ = sourcefile$ + ".ntx"
  26.    
  27.     If CreateFile(#Destfilebuff, destfile$) ; Create the destination file
  28.       WriteStringN(#Destfilebuff, "=ybegin line=128 size="+Str(sourcefilesize)+ " name="+sourcefile$ ) ; Open the yEnc section
  29.      
  30.       counter.i = 1
  31.       While Eof(#Sourcefilebuff) = 0     ; Start yEnc encodage
  32.         If counter>=128 ; Line size must be 128
  33.           counter=0
  34.           WriteAsciiCharacter(#Destfilebuff, 13)
  35.           WriteAsciiCharacter(#Destfilebuff, 10)
  36.         EndIf
  37.        
  38.         counter = counter + 1
  39.        
  40.         to_be_encoded.a = ReadAsciiCharacter(#Sourcefilebuff)
  41.         encoded.a = to_be_encoded + 42 ; yEnc formula
  42.        
  43.         Select encoded ; check if the encoded char is legit if not we must write "=" then encoded+64
  44.           Case 0, 9, 10, 13, '=', '.':
  45.             WriteAsciiCharacter(#Destfilebuff,'=') ;
  46.             WriteAsciiCharacter(#Destfilebuff,encoded+64)
  47.             counter = counter + 1
  48.           Default:
  49.             WriteAsciiCharacter(#Destfilebuff,encoded)
  50.         EndSelect
  51.    
  52.       Wend
  53.      
  54.       WriteAsciiCharacter(#Destfilebuff, 10)
  55.       result.s = Hex(CRC32FileFingerprint(sourcefile$)) ; CRC32 of the source file
  56.      
  57.       WriteStringN(#Destfilebuff, "=yend size="+Str(sourcefilesize)+" crc32="+result+" ") ; Close the yEnc section
  58.    
  59.       CloseFile(#Destfilebuff) ; Close the destination file
  60.     Else
  61.       PrintN("Couldn't create the file")
  62.     EndIf
  63.    
  64.     CloseFile(#Sourcefilebuff) ; Close the source file
  65.    
  66.     PrintN("Done!");
  67.    
  68.   Else
  69.     PrintN("Couldn't open the file!")
  70.   EndIf
  71.  
  72.   Print("Press enter to exit")
  73.   Input()
  74. EndIf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement