Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    182

    codifica 64bit...nn so + che fare...

    ho un database con passw codificate in delphi con la funzione base64...la decodifica mi da lo stesso risultato ma la codifica si differenzia dell ultima cifra!!!

    ecco i 2 algoritmi...cosa è diverso?!?

    ASP:
    Function Base64Encode(inData)

    Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789+/"
    Dim cOut, sOut, I

    'For each group of 3 bytes
    For I = 1 To Len(inData) Step 3
    Dim nGroup, pOut, sGroup

    'Create one long from this 3 bytes.
    nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
    &H100 * MyASC(Mid(inData, I + 1, 1)) + MyASC(Mid(inData, I + 2, 1))

    'Oct splits the long To 8 groups with 3 bits
    nGroup = Oct(nGroup)

    'Add leading zeros
    nGroup = String(8 - Len(nGroup), "0") & nGroup

    'Convert To base64
    pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
    Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
    Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
    Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)

    'Add the part To OutPut string
    sOut = sOut + pOut

    'Add a new line For Each 76 chars In dest (76*3/4 = 57)
    'If (I + 2) Mod 57 = 0 Then sOut = sOut + vbCrLf
    Next
    Select Case Len(inData) Mod 3
    Case 1: '8 bit final
    sOut = Left(sOut, Len(sOut) - 2) + "=="
    Case 2: '16 bit final
    sOut = Left(sOut, Len(sOut) - 1) + "="
    End Select
    Base64Encode = sOut
    End Function

    Function MyASC(OneChar)
    If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
    End Function

    ''''''''''''''''''''''''''''''''''''''''
    delphi
    '''''''''''''''''''''''''''''''''''''
    nn lo ho

  2. #2
    Utente di HTML.it L'avatar di Baol74
    Registrato dal
    Jul 2002
    Messaggi
    2,004
    Prova con la classe cBase64, questo è il codice di prova, ha due metodi Base64.Encode e Base64.Decode

    codice:
    <%
    Set Base64 = new cBase64
    s64 = Base64.Encode("CIAO")
    Response.Write s64 & "
    "
    Response.Write Base64.Decode(s64) & "
    "
    Set Base 64 = Nothing
    %>
    Il file Base64.asp

    codice:
    <%
    Class cStringBuilder
    	Private Count
    	Private arLength
    	Private arStrings()
    	
    	Public Increment
    	
    	Private Sub Class_Initialize()
    		Clear()
    	End Sub
    
    	Public Function Clear()
    		Count 			= 0
    		Increment		= 1000
    		Redim arStrings(0)
    		arLength 		= 1
    	End Function
    
    	
    	Public Sub Write(value)
    		if Count=arLength then 
    			arLength=Count+Increment
    			Redim Preserve arStrings(arLength)
    		end if
    		arStrings(Count)=value
    		Count=Count+1
    	End Sub
    	
    	
    	Public Property Let Value(strValue)
    		Clear()
    		Write strValue
    	End Property
    
    	Public default Property Get Value()
    		Value = Join(arStrings,"")
    	End Property
    	
    	Private Sub Class_Terminate()
    		Erase arStrings
    	End Sub
    
    End Class
    
    
    Class cBase64
    	Private Base64Chars
    	Private arBase64Chars
    	Private Length
    	
    	Private Sub Class_Initialize()
    		Base64Chars = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn
    opqrstuvwxyz0123456789+/"
    		arBase64Chars = Array(" ","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/")
    	End Sub
    
    	Public Function Decode(strIn)
    		Dim w1, w2, w3, w4, n, strOut
    		Set strOut = new cStringBuilder
    		Length = Len(strIn) 
    		For n = 1 To Length Step 4
    			w1 = mimedecode(Mid(strIn,n,1))
    			w2 = mimedecode(Mid(strIn,n+1,1))
    			w3 = mimedecode(Mid(strIn,n+2,1))
    			w4 = mimedecode(Mid(strIn,n+3,1))
    			If w2 >= 0 Then strOut.Write Chr(((w1 * 4 + (w2 \ 16)) And 255))
    			If w3 >= 0 Then strOut.Write Chr(((w2 * 16 + (w3 \ 4)) And 255))
    			If w4 >= 0 Then strOut.Write Chr(((w3 * 64 + w4) And 255))
    		Next
    		Decode = strOut.Value
    		Set strOut = Nothing
    	End Function
    	
    	Public Function Encode(strIn)
    		Dim c1, c2, c3, w3, w4, n , strOut , chr0 ,ar
    		Set strOut = new cStringBuilder
    		chr0 = Chr(0)
    		Length = Len(strIn) 
    		For n = 1 To Length  Step 3		
    			c1 = Asc(Mid(strIn, n, 1))
    			c2 = Asc(Mid(strIn, n + 1, 1) + chr0)
    			c3 = Asc(Mid(strIn, n + 2, 1) + chr0)
    			If Length  >= n + 1 Then 
    				w3 = (c2 And 15) * 4 + (c3 \ 64)
    			Else 
    				w3 = -1
    			End If
    			If Length >= n + 2 Then 
    				w4 = c3 And 63 
    			Else 
    				w4 = -1
    			End If
    			strOut.Write mimeencode(c1 \ 4) + mimeencode((c1 And 3) * 16 + (c2 \ 16)) + mimeencode(w3) + mimeencode(w4)
    		Next
    		on error goto 0
    		Encode = strOut.Value
    		Set strOut = Nothing
    	End Function
    	
    	Private Function mimeencode(intIn)
    		if intIn>=0 then 
    			mimeencode = arBase64Chars(intIn) 
    		else
    			mimeencode = ""
    		End if
    	End Function
    
    	Private Function mimedecode(strIn)
    		If strIn = "" Then 
    			mimedecode = -1 
    		Else
    			mimedecode = InStr(Base64Chars, strIn) - 1
    		End If
    	End Function
    	
    End Class
    %>

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2005
    Messaggi
    182

    ee

    come si usa il tutto??

    ho salvato in un nuovo file asp il codice che mi hai dato base64.asp

    le righe iniziali all inizio del file dove uso la codifica e x richiamare la funzione base64.encode(argomento)??

    tutto giusto??allora nn funge...

  4. #4
    Utente di HTML.it L'avatar di Baol74
    Registrato dal
    Jul 2002
    Messaggi
    2,004
    VVoVe:

    Metti nella stessa directory il file base64.asp e crea un file che chiami test.asp

    mettici dentro:
    codice:
    <%
    Set Base64 = new cBase64
    s64 = Base64.Encode("CIAO")
    Response.Write s64 & "
    "
    Response.Write Base64.Decode(s64) & "
    "
    Set Base 64 = Nothing
    %>
    Apri explorer e lancia la pagina test.asp

    Prima devi creare l'oggetto

    Set Base64 = new cBase64

    Puoi usi la "funzione"

    s64 = Base64.Encode("CIAO")

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.