| 
     1 // convert normal string to hex bytes string  | 
         | 
     2 def string2hex(str: String): String = { | 
         | 
     3   str.toList.map(_.toInt.toHexString).mkString  | 
         | 
     4 }  | 
         | 
     5       | 
         | 
     6 // convert hex bytes string to normal string  | 
         | 
     7   | 
         | 
     8   | 
         | 
     9 val byteArray: Array[Byte] = List.range(1, 255).map(_.toByte).toArray  | 
         | 
    10 val bos = new BufferedOutputStream(new FileOutputStream("test.txt")) | 
         | 
    11 bos.write(byteArray)  | 
         | 
    12 bos.close()   | 
         | 
    13   | 
         | 
    14   | 
         | 
    15 def string2int(hex: String) = { | 
         | 
    16   hex.sliding(2, 2).map(Integer.parseInt(_, 16)).toArray  | 
         | 
    17 }  | 
         | 
    18   | 
         | 
    19 def test(l: List[Int]) = { | 
         | 
    20   l.map(_.toChar).mkString  | 
         | 
    21 }  | 
         | 
    22   | 
         | 
    23   | 
         | 
    24 import java.io._  | 
         | 
    25 val writer = new PrintWriter(new File("test.txt" )) | 
         | 
    26   | 
         | 
    27 //writer.write(string2int("cafebabe")) | 
         | 
    28 writer.write(test(List.range(1, 255)))  | 
         | 
    29 writer.close()  | 
         | 
    30   | 
         | 
    31 import scalax.io._  | 
         | 
    32 import scalax.io.Resource  | 
         | 
    33   | 
         | 
    34 FileOutputStream fos = new FileOutputStream("test"); | 
         | 
    35 fos.write(bytesArray);  | 
         | 
    36 fos.close();  | 
         | 
    37   | 
         | 
    38   | 
         | 
    39 string2int("cafebabe") | 
         | 
    40   | 
         | 
    41 202.toHexString  | 
         | 
    42   | 
         | 
    43 "cafebabe".sliding(1, 1).toList.map(Integer.parseInt(_, 16)).map(_.toByte).map(_.toChar)  | 
         | 
    44   | 
         | 
    45 hex2string("ca") | 
         | 
    46 string2hex("ca") | 
         | 
    47 hex2string("cafebabe") | 
         | 
    48   | 
         | 
    49       | 
         | 
    50 val appkey = "9GLV//lv/kYFW2o3/bihxwnMcmo="  | 
         | 
    51           | 
         | 
    52         // string to hex  | 
         | 
    53         val appkey_hex = string2hex(appkey)  | 
         | 
    54         // 39474c562f2f6c762f6b594657326f332f62696878776e4d636d6f3d  | 
         | 
    55         println(appkey_hex)  | 
         | 
    56           | 
         | 
    57         // hex to string  | 
         | 
    58         val appkey_string_again = hex2string(appkey_hex)  | 
         | 
    59         // 9GLV//lv/kYFW2o3/bihxwnMcmo=  | 
         | 
    60         println(appkey_string_again)  | 
         | 
    61     }  | 
         | 
    62   | 
         | 
    63   | 
         | 
    64 List("ca", "fe", "ba", "be").map(_.toByte) | 
         | 
    65   | 
         | 
    66 "ca".toByte  | 
         | 
    67   | 
         | 
    68   | 
     1 // DFAs  | 
    69 // DFAs  | 
     2 import scala.util._  | 
    70 import scala.util._  | 
     3   | 
    71   | 
     4 abstract class State  | 
    72 abstract class State  | 
     5 type States = Set[State]  | 
    73 type States = Set[State]  |