วันจันทร์ที่ 27 สิงหาคม พ.ศ. 2550

VB: Password encryption

Imports System.Security.Cryptography
Imports System.Text
Imports System.IO


Public Class MyEncryptDecrypt

' Encrypt the text
Public Shared Function EncryptText(ByVal strText As String) As String
Return Encrypt(strText, "&%#@?,:*")
End Function
'Decrypt the text
Public Shared Function DecryptText(ByVal strText As String) As String
Return Decrypt(strText, "&%#@?,:*")
End Function
'The function used to encrypt the text
Private Shared Function Encrypt(ByVal strText As String, ByVal
strEncrKey As String) As String
Dim byKey() As Byte = {}
Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
Try
byKey = System.Text.Encoding.UTF8.GetBytes(Left(strEncrKey , 8))
Dim des As New DESCryptoServiceProvider
Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(strText)
Dim ms As New MemoryStream
Dim cs As New CryptoStream(ms, des.CreateEncryptor(byKey, IV),
CryptoStreamMode.Write)
cs.Write(inputByteArray, 0, inputByteArray.Length)
cs.FlushFinalBlock()
Return Convert.ToBase64String(ms.ToArray())
Catch ex As Exception
Return ex.Message
End Try
End Function
'The function used

Java:Caculator

public class Chardonnay extends javax.swing.JFrame { */
public Chardonnay() {
initComponents();
}
private void initComponents() {
groupOperator = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
labelResult = new javax.swing.JLabel();
radioDivide = new javax.swing.JRadioButton();
radioMultiply = new javax.swing.JRadioButton();
radioSubtract = new javax.swing.JRadioButton();
radioAdd = new javax.swing.JRadioButton();
editY = new javax.swing.JTextFiel

VB.net:ImportFile

Class TextFileImporter
Public Function ImportFile() As ValidationIssuesList
'For each line in file, parse data into in-memory DataTable Using fileReader As New IO.StreamReader(m_filePath)
Try
Do While fileReader.Peek() >= 0 CurrentLineNumber += 1
'Read next line of text from file Dim strLineText As String = fileReader.ReadLine
'Importing the line into the DataTable ImportLine(strLineText)
Loop
Catch ex As Exception RecordImportIssueForCurrentLine(New _ ValidationIssue(String.Format("Error occurred" & _ " during import of file: {0}", ex.Message)))
End Try
End Using
Return m_importIssues End Function
Protected Sub ImportLine(ByVal LineText As String)
Dim row As DataRow = m_data.NewRow Try 'Parse data into a string array Dim astrValues As String() astrValues = ParseValuesFromLine(LineText)
'Put values from string array into data PutValuesInRow(row, astrValues)
'Validate data ValidateDataRow(row)
'Store valid data into table m_data.Rows.Add(row)
Catch ex As Exception RecordImportIssueForCurrentLine(New _ ValidationIssue("Error during import: " & ex.Message))
End Try
End Sub
Protected MustOverride Function ParseValuesFromLine(ByVal _ LineText As String) As String()
End Class