---------- Naloga 9.9 #include <stdio.h> #include <stdlib.h> int main(void) { char sporocilo[100]; int i, kljuc, n = 0; system("chcp 65001"); printf("Vnesi sporočilo:\n"); gets(sporocilo); printf("Vnesi ključ:\n"); for(i = 0; sporocilo[i]; i = i + 1) { scanf("%X", &kljuc); if(i == 0) printf("Šifrirano sporočilo:\n"); printf("%02X ", sporocilo[i] ^ kljuc); } printf("\n\nVnesi šifrirano sporočilo:\n"); do { scanf("%X", &kljuc); sporocilo[n++] = kljuc; } while(getchar() != '\n'); printf("Vnesi ključ:\n"); for(i = 0; i < n; i = i + 1) { scanf("%X", &kljuc); if(i == 0) printf("Dešifrirano sporočilo:\n"); printf("%c", sporocilo[i] ^ kljuc); } printf("\n"); return 0; } ---------- Naloga 11.4 /* TinkerCAD connections: * arduino 2 pushbutton t0 1a * arduino 3 pushbutton t1 1a * arduino 4 pushbutton t2 1a * arduino GND pushbutton t0 2a * arduino GND pushbutton t1 2a * arduino GND pushbutton t2 2a * arduino 5 r0 1 (220ohm) * arduino 6 r1 1 (220ohm) * arduino 7 r2 1 (220ohm) * r0 2 (220ohm) led0 Anode * r1 2 (220ohm) led1 Anode * r2 2 (220ohm) led2 Anode * arduino GND led0 Cathode * arduino GND led1 Cathode * arduino GND led2 Cathode */ void setup(void) { DDRD &= 0xE3; /* D2, D3 and D4 are inputs */ PORTD |= 0x1C; /* D2, D3 and D4 have pull-ups */ DDRD |= 0xE0; /* D5, D6 and D7 are outputs */ } void loop(void) { PORTD = PORTD & 0x1F | (~PIND & 0x1C) << 3; } ---------- Naloga 11.9 /* TinkerCAD connections: * arduino 13 lcd RS * arduino 12 lcd E * arduino 11 lcd DB4 * arduino 10 lcd DB5 * arduino 9 lcd DB6 * arduino 8 lcd DB7 * arduino 7 keypad column 1 * arduino 6 keypad column 2 * arduino 5 keypad column 3 * arduino 4 keypad column 4 * arduino 3 keypad row 1 * arduino 2 keypad row 2 * arduino 1 keypad row 3 * arduino 0 keypad row 4 * arduino GND lcd GND * lcd GND lcd V0 * lcd V0 lcd R/W * lcd R/W lcd LED Cathode * arduino 5V lcd VCC * arduino 5V r1 1 (220 ohm) * r1 2 (220ohm) lcd LED Anode */ #define RS 13 #define E 12 #define DB4 11 #define DB5 10 #define DB6 9 #define DB7 8 #define ST0 7 #define ST1 6 #define ST2 5 #define ST3 4 #define VR0 3 #define VR1 2 #define VR2 1 #define VR3 0 #define ST_VRSTIC 4 #define ST_STOLPCEV 4 #include <LiquidCrystal.h> unsigned char g_st[ST_STOLPCEV] = {ST0, ST1, ST2, ST3}; unsigned char g_vr[ST_VRSTIC] = {VR0, VR1, VR2, VR3}; LiquidCrystal g_lcd(RS, E, DB4, DB5, DB6, DB7); void izberiVrstico(int v) { int i; for(i = 0; i < ST_VRSTIC; i = i + 1) if(i == v) { pinMode(g_vr[i], OUTPUT); digitalWrite(g_vr[i], LOW); } else pinMode(g_vr[i], INPUT); } unsigned short int beriTipke(void) { unsigned short int v, s, m, tipke = 0; for(v = 0; v < ST_VRSTIC; v = v + 1) { izberiVrstico(v); tipke = tipke << 4; for(s = 0, m = 0x08; s < ST_STOLPCEV; s = s + 1, m = m >> 1) if(digitalRead(g_st[s]) == LOW) tipke = tipke | m; } return tipke; } void setup(void) { int i; g_lcd.begin(16, 2); for(i = 0; i < ST_STOLPCEV; i = i + 1) pinMode(g_st[i], INPUT_PULLUP); } void loop(void) { unsigned short int i, t = beriTipke(); g_lcd.clear(); for(i = 0x8000; i > t; i = i >> 1) g_lcd.print(0); /* Izpis vodilnih ničel. */ g_lcd.print(t, BIN); delay(200); } ----------