Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $large
  2. $sim
  3. $eeprom
  4.  
  5. Deflcdchar 0 , 12 , 4 , 6 , 12 , 4 , 4 , 14 , 32            
  6. Deflcdchar 1 , 2 , 4 , 14 , 16 , 14 , 1 , 30 , 32          
  7. Deflcdchar 2 , 2 , 4 , 14 , 16 , 16 , 17 , 14 , 32          
  8. Deflcdchar 3 , 32 , 32 , 14 , 17 , 31 , 16 , 14 , 4        
  9. Deflcdchar 4 , 32 , 32 , 15 , 17 , 17 , 15 , 1 , 14         'g
  10. Deflcdchar 5 , 2 , 4 , 31 , 2 , 4 , 8 , 31 , 32            
  11. Deflcdchar 6 , 2 , 4 , 14 , 17 , 17 , 17 , 14 , 32          
  12. Deflcdchar 7 , 4 , 32 , 31 , 2 , 4 , 8 , 31 , 32            
  13. 'Deflcdchar ? , 32 , 32 , 14 , 1 , 15 , 17 , 15 , 2            'ą
  14.  
  15. Config Porta = Input
  16. Config Portb = Output
  17.  
  18. Config Lcd = 16 * 2
  19. 'Config Lcdpin = Pin , Db4 = P3.4 , Db5 = P3.5 , Db6 = P3.6 , Db7 = P3.7 , E = P3.3 , Rs = P3.1   'konfig z zajec
  20. Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portb.2 , Rs = Portb.0
  21.  
  22. 'Set Porta
  23.  
  24. Dim Dlugosc As Byte
  25. Dim Stan As Byte
  26. Dim Flaga As Bit
  27. Dim I As Byte
  28. Dim J As Byte
  29. Dim Tajnyszyfriterator As Byte
  30.  
  31. Dim Szyfr(9) As Byte
  32. Dim Szyfruser(9) As Byte
  33. Dim Tajnyszyfr(16) As Byte
  34. Dim Tajnyszyfruser(16) As Byte
  35. '-------------------------------------------
  36. Const Wsk_flaga = &H00
  37. Const Wsk_1 = &H01
  38. Const Wsk_2 = &H02
  39. Const Wsk_3 = &H03
  40. Const Wsk_4 = &H04
  41. Const Wsk_5 = &H05
  42. Const Wsk_6 = &H06
  43. Const Wsk_7 = &H07
  44. Const Wsk_8 = &H08
  45. Const Wsk_9 = &H09
  46.  
  47. Dim Szyfr_pamiec(9) As Byte
  48. Szyfr_pamiec(1) = Wsk_1
  49. Szyfr_pamiec(2) = Wsk_2
  50. Szyfr_pamiec(3) = Wsk_3
  51. Szyfr_pamiec(4) = Wsk_4
  52. Szyfr_pamiec(5) = Wsk_5
  53. Szyfr_pamiec(6) = Wsk_6
  54. Szyfr_pamiec(7) = Wsk_7
  55. Szyfr_pamiec(8) = Wsk_8
  56. Szyfr_pamiec(9) = Wsk_9
  57.  
  58. Dim Flaga_eprom As Byte
  59. Flaga_eprom = 1
  60.  
  61. '--------------------------------------------
  62.  
  63. Tajnyszyfr(1) = 1
  64. Tajnyszyfr(2) = 2
  65. Tajnyszyfr(3) = 3
  66. Tajnyszyfr(4) = 4
  67. Tajnyszyfr(5) = 5
  68. Tajnyszyfr(6) = 6
  69. Tajnyszyfr(7) = 7
  70. Tajnyszyfr(8) = 8
  71. Tajnyszyfr(9) = 1
  72. Tajnyszyfr(10) = 2
  73. Tajnyszyfr(11) = 3
  74. Tajnyszyfr(12) = 4
  75. Tajnyszyfr(13) = 5
  76. Tajnyszyfr(14) = 6
  77. Tajnyszyfr(15) = 7
  78. Tajnyszyfr(16) = 8
  79.  
  80. Stan = 0
  81. Dlugosc = 0
  82. Flaga = 0
  83. ' tablice w bascomie zaczynają się od 1 xDDD
  84. I = 1
  85. Tajnyszyfriterator = 1
  86.  
  87. Declare Sub Wprowadz_dlugosc
  88. Declare Sub Wprowadz_szyfr1
  89. Declare Sub Wprowadz_szyfr2
  90. Declare Sub Sprawdz_szyfr
  91. Declare Sub Wprowadz_szyfr_otwieranie
  92. Declare Sub Sprawdz_szyfr_otwieranie
  93. Declare Sub Zmiana_szyfru
  94.  
  95. Dim Pom As Byte
  96. Dim Pom2 As Byte
  97. Pom2 = 16
  98. '-----------------------------------------------------
  99. ' if eprom == 0 to stan = 0
  100. ' jezeli w epromie cos jest to stan = 3 i uzupelniamy tablice "szyfr" zawartoscia epromu
  101.  
  102.  
  103. 'zapisane_halo to flaga z adresu pamieci w ktorym trzymam info o tym czy haslojest zapisane w pamieci,
  104. ' jesli 1 to zapisane
  105.  
  106. Dim Zapisane_haslo As Byte
  107. Readeeprom Zapisane_haslo , Wsk_flaga
  108.  
  109. If Zapisane_haslo = 1 Then
  110.    Stan = 3
  111.    Tajnyszyfriterator = 2 + Rnd(16)
  112.    For I = 1 To 9
  113.       Readeeprom Szyfr(i) , Szyfr_pamiec(i)
  114.    Next
  115. Else
  116.    Stan = 0
  117. End If
  118. '-------------------------------------------------------
  119.  
  120. ' aby zmienic haslo nalezy najpierw podac poprawny szyfr, a nastepnie podac tajny szyfr
  121.  
  122. ' main
  123. Do
  124.    Main:
  125.    Pom = Dlugosc + 1
  126.  
  127.    If Tajnyszyfriterator = 17 Then Call Zmiana_szyfru
  128.  
  129.    If Stan = 0 Then Call Wprowadz_dlugosc
  130.    If Stan = 1 Then Call Wprowadz_szyfr1
  131.    If Stan = 2 Then Call Wprowadz_szyfr2
  132.    If Stan = 3 Then Call Wprowadz_szyfr_otwieranie
  133.  
  134.    'Print "dlugosc=" ; Dlugosc ; " i=" ; I ; " TajnySzyfrIterator=" ; Tajnyszyfriterator
  135.  
  136. Loop
  137. End
  138.  
  139. ' wprowadzanie dlugosci
  140. Sub Wprowadz_dlugosc
  141.  
  142.    If Flaga = 0 Then
  143.       Cls
  144.       Lcd "Jak d" ; Chr(0) ; "u" ; Chr(4) ; "i szyfr?"
  145.       Lowerline
  146.       Lcd "  D" ; Chr(0) ; "u" ; Chr(4) ; "o" ; Chr(1) ; Chr(2) ; ": "
  147.       Flaga = 1
  148.    End If
  149.  
  150.    If Porta.0 = 1 Then
  151.       Bitwait Porta.0 , Reset
  152.       Cls
  153.       Lcd " D" ; Chr(0) ; "u" ; Chr(4) ; "o" ; Chr(1) ; Chr(2) ; " szyfru "
  154.       Lowerline
  155.       Lcd " Pomi" ; Chr(3) ; "dzy 4 a 8 "
  156.       Wait 5
  157.       Flaga = 0
  158.       Goto Main
  159.    End If
  160.  
  161.    If Porta.1 = 1 Then
  162.       Bitwait Porta.1 , Reset
  163.       Cls
  164.       Lcd " D" ; Chr(0) ; "u" ; Chr(4) ; "o" ; Chr(1) ; Chr(2) ; " szyfru "
  165.       Lowerline
  166.       Lcd " Pomi" ; Chr(3) ; "dzy 4 a 8 "
  167.       Wait 5
  168.       Flaga = 0
  169.       Goto Main
  170.    End If
  171.  
  172.    If Porta.2 = 1 Then
  173.       Bitwait Porta.2 , Reset
  174.       Cls
  175.       Lcd " D" ; Chr(0) ; "u" ; Chr(4) ; "o" ; Chr(1) ; Chr(2) ; " szyfru "
  176.       Lowerline
  177.       Lcd " Pomi" ; Chr(3) ; "dzy 4 a 8 "
  178.       Wait 5
  179.       Flaga = 0
  180.       Goto Main
  181.    End If
  182.  
  183.    If Porta.3 = 1 Then
  184.       Bitwait Porta.3 , Reset
  185.       Lcd "4"
  186.       Dlugosc = 5
  187.       Stan = 1
  188.       Flaga = 0
  189.    End If
  190.  
  191.    If Porta.4 = 1 Then
  192.       Bitwait Porta.4 , Reset
  193.       Lcd "5"
  194.       Dlugosc = 6
  195.       Stan = 1
  196.       Flaga = 0
  197.    End If
  198.  
  199.    If Porta.5 = 1 Then
  200.       Bitwait Porta.5 , Reset
  201.       Lcd "6"
  202.       Dlugosc = 7
  203.       Stan = 1
  204.       Flaga = 0
  205.    End If
  206.  
  207.    If Porta.6 = 1 Then
  208.       Bitwait Porta.6 , Reset
  209.       Lcd "7"
  210.       Dlugosc = 8
  211.       Stan = 1
  212.       Flaga = 0
  213.    End If
  214.  
  215.    If Porta.7 = 1 Then
  216.       Bitwait Porta.7 , Reset
  217.       Lcd "8"
  218.       Dlugosc = 9
  219.       Stan = 1
  220.       Flaga = 0
  221.    End If
  222.  
  223.  
  224. End Sub
  225.  
  226. ' wprowadzanie szyfru
  227. Sub Wprowadz_szyfr1
  228.  
  229.    If Flaga = 0 Then
  230.       Cls
  231.       Lcd "  Podaj szyfr"
  232.       Lowerline
  233.       Lcd "Szyfr: "
  234.       Flaga = 1
  235.    End If
  236.  
  237.    If I = Dlugosc Then
  238.       Stan = 2
  239.       Flaga = 0
  240.       I = 1
  241.       Goto Main
  242.    End If
  243.  
  244.    If Porta.0 = 1 Then
  245.       Bitwait Porta.0 , Reset
  246.       Lcd "#"
  247.       Szyfr(i) = 1
  248.       Incr I
  249.    End If
  250.  
  251.    If Porta.1 = 1 Then
  252.       Bitwait Porta.1 , Reset
  253.       Lcd "#"
  254.       Szyfr(i) = 2
  255.       Incr I
  256.    End If
  257.  
  258.    If Porta.2 = 1 Then
  259.       Bitwait Porta.2 , Reset
  260.       Lcd "#"
  261.       Szyfr(i) = 3
  262.       Incr I
  263.    End If
  264.  
  265.    If Porta.3 = 1 Then
  266.       Bitwait Porta.3 , Reset
  267.       Lcd "#"
  268.       Szyfr(i) = 4
  269.       Incr I
  270.    End If
  271.  
  272.    If Porta.4 = 1 Then
  273.       Bitwait Porta.4 , Reset
  274.       Lcd "#"
  275.       Szyfr(i) = 5
  276.       Incr I
  277.    End If
  278.  
  279.    If Porta.5 = 1 Then
  280.       Bitwait Porta.5 , Reset
  281.       Lcd "#"
  282.       Szyfr(i) = 6
  283.       Incr I
  284.    End If
  285.  
  286.    If Porta.6 = 1 Then
  287.       Bitwait Porta.6 , Reset
  288.       Lcd "#"
  289.       Szyfr(i) = 7
  290.       Incr I
  291.    End If
  292.  
  293.    If Porta.7 = 1 Then
  294.       Bitwait Porta.7 , Reset
  295.       Lcd "#"
  296.       Szyfr(i) = 8
  297.       Incr I
  298.    End If
  299.  
  300.  
  301. End Sub
  302.  
  303. ' potwierdzanie szyfru
  304. Sub Wprowadz_szyfr2
  305.  
  306.    If Flaga = 0 Then
  307.       Flaga = 1
  308.       Cls
  309.       Lcd " Potwierd" ; Chr(5) ; " szyfr"
  310.       Lowerline
  311.       Lcd "Szyfr: "
  312.       Flaga = 1
  313.    End If
  314.  
  315.    If I = Dlugosc Then
  316.       Stan = 2
  317.       Flaga = 0
  318.       I = 1
  319.       Call Sprawdz_szyfr
  320.    End If
  321.  
  322.    If Porta.0 = 1 Then
  323.       Bitwait Porta.0 , Reset
  324.       Lcd "#"
  325.       Szyfruser(i) = 1
  326.       Incr I
  327.    End If
  328.  
  329.    If Porta.1 = 1 Then
  330.       Bitwait Porta.1 , Reset
  331.       Lcd "#"
  332.       Szyfruser(i) = 2
  333.       Incr I
  334.    End If
  335.  
  336.    If Porta.2 = 1 Then
  337.       Bitwait Porta.2 , Reset
  338.       Lcd "#"
  339.       Szyfruser(i) = 3
  340.       Incr I
  341.    End If
  342.  
  343.    If Porta.3 = 1 Then
  344.       Bitwait Porta.3 , Reset
  345.       Lcd "#"
  346.       Szyfruser(i) = 4
  347.       Incr I
  348.    End If
  349.  
  350.    If Porta.4 = 1 Then
  351.       Bitwait Porta.4 , Reset
  352.       Lcd "#"
  353.       Szyfruser(i) = 5
  354.       Incr I
  355.    End If
  356.  
  357.    If Porta.5 = 1 Then
  358.       Bitwait Porta.5 , Reset
  359.       Lcd "#"
  360.       Szyfruser(i) = 6
  361.       Incr I
  362.    End If
  363.  
  364.    If Porta.6 = 1 Then
  365.       Bitwait Porta.6 , Reset
  366.       Lcd "#"
  367.       Szyfruser(i) = 7
  368.       Incr I
  369.    End If
  370.  
  371.    If Porta.7 = 1 Then
  372.       Bitwait Porta.7 , Reset
  373.       Lcd "#"
  374.       Szyfruser(i) = 8
  375.       Incr I
  376.    End If
  377.  
  378. End Sub
  379.  
  380. ' sprawdzanie czy podany szyfr zgadza sie z jego potwierdzeniem
  381. Sub Sprawdz_szyfr
  382.  
  383.    Flaga = 0
  384.  
  385.    For J = 1 To Dlugosc
  386.       If Szyfr(j) <> Szyfruser(j) Then
  387.          Flaga = 0
  388.          Exit For
  389.       Else
  390.          Flaga = 1
  391.       End If
  392.       'Print "J=" ; J ; " " ; Szyfr(j) ; " " ; Szyfruser(j) ; " flaga= " ; Flaga
  393.    Next J
  394.  
  395.    'Print "flaga=" ; Flaga
  396.  
  397.    If Flaga = 0 Then
  398.       Cls
  399.       Lcd " Podano r" ; Chr(6) ; Chr(7) ; "ne "
  400.       Lowerline
  401.       Lcd "     szyfry!    "
  402.       Wait 5
  403.       Stan = 0
  404.       Flaga = 0
  405.       I = 1
  406.    Else
  407.       Cls
  408.       Lcd "  Szyfr zosta" ; Chr(0) ; "  "
  409.       Lowerline
  410.       Lcd "   ustawiony!   "
  411.       '------------------------------------------------------------------
  412.       ' Tutaj zrobić zapis tablicy "Szyfr" do EPROM!!!'
  413.  
  414.       Tajnyszyfriterator = 2 + Rnd(16)
  415.  
  416.       For I = 1 To 9
  417.          Writeeeprom Szyfr(i) , Szyfr_pamiec(i)
  418.       Next
  419.  
  420.       Writeeeprom Flaga_eprom , Wsk_flaga
  421.  
  422.       '-----------------------------------------------------------------
  423.       Wait 5
  424.       Stan = 3
  425.       Flaga = 0
  426.       I = 1
  427.    End If
  428.  
  429. End Sub
  430.  
  431. ' domyslny tryb pracy (otwieranie sejfu jezeli szyfr jest poprawny)
  432. Sub Wprowadz_szyfr_otwieranie
  433.  
  434.    If Flaga = 0 Then
  435.       Cls
  436.       Lcd "  Podaj szyfr"
  437.       Lowerline
  438.       Lcd "Szyfr: "
  439.       Flaga = 1
  440.    End If
  441.  
  442.    If I = Dlugosc Then
  443.       Stan = 2
  444.       Flaga = 0
  445.       I = 1
  446.       Call Sprawdz_szyfr_otwieranie
  447.    End If
  448.  
  449.    If Porta.0 = 1 Then
  450.       Bitwait Porta.0 , Reset
  451.       Lcd "#"
  452.       Szyfruser(i) = 1
  453.       Incr I
  454.       Tajnyszyfruser(tajnyszyfriterator) = 1
  455.       Incr Tajnyszyfriterator
  456.    End If
  457.  
  458.    If Porta.1 = 1 Then
  459.       Bitwait Porta.1 , Reset
  460.       Lcd "#"
  461.       Szyfruser(i) = 2
  462.       Incr I
  463.       Tajnyszyfruser(tajnyszyfriterator) = 2
  464.       Incr Tajnyszyfriterator
  465.    End If
  466.  
  467.    If Porta.2 = 1 Then
  468.       Bitwait Porta.2 , Reset
  469.       Lcd "#"
  470.       Szyfruser(i) = 3
  471.       Incr I
  472.       Tajnyszyfruser(tajnyszyfriterator) = 3
  473.       Incr Tajnyszyfriterator
  474.    End If
  475.  
  476.    If Porta.3 = 1 Then
  477.       Bitwait Porta.3 , Reset
  478.       Lcd "#"
  479.       Szyfruser(i) = 4
  480.       Incr I
  481.       Tajnyszyfruser(tajnyszyfriterator) = 4
  482.       Incr Tajnyszyfriterator
  483.    End If
  484.  
  485.    If Porta.4 = 1 Then
  486.       Bitwait Porta.4 , Reset
  487.       Lcd "#"
  488.       Szyfruser(i) = 5
  489.       Incr I
  490.       Tajnyszyfruser(tajnyszyfriterator) = 5
  491.       Incr Tajnyszyfriterator
  492.    End If
  493.  
  494.    If Porta.5 = 1 Then
  495.       Bitwait Porta.5 , Reset
  496.       Lcd "#"
  497.       Szyfruser(i) = 6
  498.       Incr I
  499.       Tajnyszyfruser(tajnyszyfriterator) = 6
  500.       Incr Tajnyszyfriterator
  501.    End If
  502.  
  503.    If Porta.6 = 1 Then
  504.       Bitwait Porta.6 , Reset
  505.       Lcd "#"
  506.       Szyfruser(i) = 7
  507.       Incr I
  508.       Tajnyszyfruser(tajnyszyfriterator) = 7
  509.       Incr Tajnyszyfriterator
  510.    End If
  511.  
  512.    If Porta.7 = 1 Then
  513.       Bitwait Porta.7 , Reset
  514.       Lcd "#"
  515.       Szyfruser(i) = 8
  516.       Incr I
  517.       Tajnyszyfruser(tajnyszyfriterator) = 8
  518.       Incr Tajnyszyfriterator
  519.    End If
  520.  
  521. End Sub
  522.  
  523. ' sprawdzanie czy podany przez uzytkownika szyfr jest poprawny
  524. Sub Sprawdz_szyfr_otwieranie
  525.  
  526.    Flaga = 0
  527.  
  528.    For J = 1 To Dlugosc
  529.       If Szyfr(j) <> Szyfruser(j) Then
  530.          Flaga = 0
  531.          Exit For
  532.       Else
  533.          Flaga = 1
  534.       End If
  535.    Next J
  536.  
  537.    If Flaga = 1 Then
  538.       Cls
  539.       Lcd "   Otwarte :)   "
  540.       Wait 60
  541.       Stan = 3
  542.       Flaga = 0
  543.       I = 1
  544.       Tajnyszyfriterator = 1
  545.    Else
  546.    '-------------------SEBA-----------doisac sprawdzanie czy tajny szyfr jest poprawnie wprowadzany jesli nie to losowac liczbe
  547.       Cls
  548.       Lcd "  Podano b" ; Chr(0) ; Chr(3) ; "dny  "
  549.       Lowerline
  550.       Lcd "     szyfr!   "
  551.       Wait 5
  552.       Stan = 3
  553.       Flaga = 0
  554.       I = 1
  555.    End If
  556.  
  557. End Sub
  558.  
  559. ' sprawdzanie czy ukryty szyfr jest poprawny
  560. Sub Zmiana_szyfru
  561.  
  562.    Tajnyszyfriterator = 1
  563.    Flaga = 0
  564.    'Break
  565.  
  566.    For J = 1 To Pom2
  567.       If Tajnyszyfr(j) <> Tajnyszyfruser(j) Then
  568.          Flaga = 0
  569.          Exit For
  570.       Else
  571.          Flaga = 1
  572.       End If
  573.       'Print Tajnyszyfr(j) ; " " ; Tajnyszyfruser(j)
  574.    Next J
  575.  
  576.    For J = 1 To Pom2
  577.       'Print "TajnySzyfr= " ; Tajnyszyfr(j) ; " " ; "TajnySzyfrUser= " ; Tajnyszyfruser(j)
  578.    Next J
  579.  
  580.    If Flaga = 1 Then
  581.       Cls
  582.       Lcd "  wprowadzono   "
  583.       Lowerline
  584.       Lcd "  tajny szyfr   "
  585.       Wait 4
  586.       Flaga = 0
  587.       I = 1
  588.       Stan = 0
  589.       Goto Main
  590.    End If
  591.  
  592. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement