{"id":23094156,"url":"https://github.com/leivosepp/octal-clock-two-bytes-24h","last_synced_at":"2025-04-03T19:19:08.944Z","repository":{"id":132646932,"uuid":"325652108","full_name":"LeivoSepp/Octal-Clock-Two-Bytes-24h","owner":"LeivoSepp","description":"Two bytes clock used by Paradox Security systems. Include special generator. Weird system. Useless.","archived":false,"fork":false,"pushed_at":"2021-01-16T10:05:37.000Z","size":2433,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-19T12:53:23.615Z","etag":null,"topics":["byte","clock","paradox-security"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LeivoSepp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-30T21:32:34.000Z","updated_at":"2021-01-16T10:05:39.000Z","dependencies_parsed_at":"2023-07-29T22:27:21.226Z","dependency_job_id":null,"html_url":"https://github.com/LeivoSepp/Octal-Clock-Two-Bytes-24h","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeivoSepp%2FOctal-Clock-Two-Bytes-24h","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeivoSepp%2FOctal-Clock-Two-Bytes-24h/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeivoSepp%2FOctal-Clock-Two-Bytes-24h/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeivoSepp%2FOctal-Clock-Two-Bytes-24h/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeivoSepp","download_url":"https://codeload.github.com/LeivoSepp/Octal-Clock-Two-Bytes-24h/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247061882,"owners_count":20877176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["byte","clock","paradox-security"],"created_at":"2024-12-16T21:57:12.166Z","updated_at":"2025-04-03T19:19:08.916Z","avatar_url":"https://github.com/LeivoSepp.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Two Bytes Clock 24h\nThis two bytes clock is used by the Paradox Security systems.\n![Paradox](Readme/Paradox.png)\n\n### Two bytes for a clock\n\nThese two bytes has to be a clock but I didn't know how?\n\nByte1 : Byte2 = 0000 0000 : 0000 0000\n\n### Algorithm\n\n* Bits 1-4 are always zeros.\n* Bits 5-10 are minute.\n* Bit 11 is zero.\n* Bits 12-16 are hour.\n\n|0000 |0000 | 0000 | 0000 |\n|-|-|-|-|\n|HHHH |H0mm | mmmm | 0000 |\n\nGraphical view of this.\n\n\u003cimg src=\"Readme/binary_solution1.png\" alt=\"drawing\" width=\"200\"/\u003e\n\nSome examples\n\n|Time|Byte1-Byte2|\n|---|---|\n| 00:00 | 00000000-00000000 |\n| 00:01 | 00000000-00010000 |\n| 00:02 | 00000000-00100000 |\n| 00:03 | 00000000-00110000 |\n|...|...|\n| 00:15 | 00000000-11110000 |\n| 00:16 | 00000001-00000000 |\n| 00:17 | 00000001-00010000 |\n|...|...|\n| 00:31 | 00000001-11110000 |\n| 00:32 | 00000010-00000000 |\n| 00:33 | 00000010-00010000 |\n|...|...|\n| 00:47 | 00000010-11110000 |\n| 00:48 | 00000011-00000000 |\n| 00:49 | 00000011-00010000 |\n|...|...|\n| 00:58 | 00000011-10100000 |\n| 00:59 | 00000011-10110000 |\n| 01:00 | 00001000-00000000 |\n| 01:01 | 00001000-00010000 |\n| 01:02 | 00001000-00100000 |\n|...|...|\n| 23:59 | 10111011-10110000 |\n\n### Two Solutions\nThere are two different solutions. \n1. Traditional shift-operation with binary numbers. \n2. Mathemathical calculation. This was an initial solution.\n\n#### 1. Traditional binary shift operations\nLook at the numbers in binary format. The clock is very simple.\n\nGetting hours and minutes with traditional binary shift operations.\n```c#\n//getting minute and hour with shift operations\nint tHour = Byte1 \u003e\u003e 3;\nint tMinute = ((Byte1 \u0026 3) \u003c\u003c 4) + (Byte2 \u003e\u003e 4);\nstring time = $\"{(tHour \u003c 10 ? $\"0{tHour}\" : $\"{tHour}\")}:{(tMinute \u003c 10 ? $\"0{tMinute}\" : $\"{tMinute}\")}\";\n```\n\nAnother way is to create one 16 bit number and then shift the clock from that number.\n```c#\n//creating one 16 bit number and then reading clock from that number\nint twoBytes = (Byte1 \u003c\u003c 8) + Byte2;\nint tHour = twoBytes \u003e\u003e 11;\nint tMinute = (twoBytes \u0026 0x3F0) \u003e\u003e 4;\n```\n\n#### 2. Mathemathical\nWhen I started to solve the problem, then I figured out following pattern.\n1. Byte2 is increasing in every minute by 16 bit. \u003cbr\u003e\nOne way to show it is to use octal numeric system by adding 20 in every minute. (OCT) 00 20 40 60 100\n2. When Byte2 reach it's maximum (OCT) 360 then one bit is added to Byte1. \u003cbr\u003e\nOne bit is added into Byte1 in every 16 minute. One hour is: Byte1 increased by 3 bit and Byte2 increased by 176 bit.\n3. Every hour the Byte1 will increase by 8 bit or by 10 (OCT). (OCT) 0h - 0; 1h - 10; 2h - 20; .. 8h - 100.\n\nReverse engineering found that the clock was is easier to understand if using octal numeral system. \nAnyway, this is how I started. \nTo solve this mathemathical clock challenge the first task was to build the clock generator.\n\nOctal numeric system? Huhh, crazy thing. \nDo you know what is Octal numeric system? The numbers are going up only to 7 and after that comes 10.\n\u003eOctal 0,1,2,3,4,5,6,7,10,11,12,13,14,15,16,17 ...\n\nSome time examples:\n* time 23:59 is in Octal 273 260 and in Hex 0xBB 0xB0.\n* time 8:00 is in Octal 100 and in Hex 0x08.\n* time 20:00 is in Otal 240 and in Hex 0xA0.\n\nThe final solution is a geniusly simple as it has just two lines of code (hours and minutes) with a little mathematics. \nThis solution is giving exactly same output as the first solution but the first one is obviously better. \n\n```c#\n//getting minute and hour in mathemathical way\nint hour = Byte1 / 8;\nint minute = Byte1 % 8 * 16 + Byte2 / 16;\n```\n\nOutput of this program.\n\n![Output1](Readme/output1.png)\n## Thanks, Paradox\n\nThanks, Paradox for this challenge. Math is cool. Learn it and you will understand it.\n\nThis project is related directly with my Paradox Security System Spectra 1738 serial output reverse engineering project.\u003c/br\u003e\nhttps://github.com/LeivoSepp/Paradox-Spectra-1738-SerialOutput \n\n### Resources used during the project\nWorking with octal, byte, hex numbers.\n\nThese links were used to build the octal generator for a clock reverse engineering.\u003c/br\u003e\nhttps://stackoverflow.com/questions/34362859/add-two-octal-numbers-directly-without-converting-to-decimal \u003c/br\u003e\nhttps://stackoverflow.com/questions/3781764/how-can-we-convert-binary-number-into-its-octal-number-using-c \u003c/br\u003e\nhttps://docs.microsoft.com/en-us/dotnet/api/system.bitconverter.tostring?view=net-5.0 \u003c/br\u003e\nhttps://stackoverflow.com/questions/1139957/convert-integer-to-hexadecimal-and-back-again \u003c/br\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleivosepp%2Foctal-clock-two-bytes-24h","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleivosepp%2Foctal-clock-two-bytes-24h","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleivosepp%2Foctal-clock-two-bytes-24h/lists"}