Autor Beitrag
Karl Lynen
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Do 20.08.09 17:52 
Guten Tag,

Ich hoffe ihr könnt mir bei meiner Frage behilflich sein.

Ich soll ein Programm schreiben, dass einen "Normaltext" in "Morsetext" verwandelt.

zB. I N F O >>> .. -. ..-. ---

Wir sollen einen Encodierer und einen Decodierer entwickeln.

Leider habe ich keine genaue Ahnung wie ich das anstellen soll.

Könntet ihr mir bitte weiterhelfen?


Vielen Dank :)
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Do 20.08.09 17:58 
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 480

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 20.08.09 18:08 
Ich schmeiß einfach mal StringReplace in den Raum. So ganz grob: Ein Record-Typ definieren, der Buchstaben und zugehöriges Morsezeichen (plus ein Leerzeichen) enthält, dann davon ein Array der Länge 26 bauen, und dann den Code
ausblenden Delphi-Quelltext
1:
2:
for i := 0 to 25 do
  aText := StringReplace(aText, MorseArray[i].Char, MorseArray[i].Morsecode, rfReplaceAll);


Die andere Richtung genauso. Geschwindigkeitsrekorde wirst du damit nicht aufstellen, aber das sollte für kleine Texte klappen - da kann man ja auch mal was gröber arbeiten. :angel:

_________________
We are, we were and will not be.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 20.08.09 19:55 
Eine alternative und einfach zu bewerkstelligen Lösung stellt folgende dar:
Du definierst in einem Array alle 26 verschiedene Morse-Zeichen, wodurch du jedem Zeichen einen eindeutigen Index (wie im Alphabet) zuordnest.
Nun musst Du nur noch mit der Funktion Ord() (Gegenteil ist Chr()) den ASCII-Zeichencode des entsprechenden Chars bestimmen, um mittels diesem an dessen Index im Alphabet zu kommen.

Ich hoffe das ist verständlich und Du kommst damit weiter. :)

Grüße,
Marc
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Do 20.08.09 21:14 
Bissle, Offtopic, aber erinnert mich an das Adventsrätsel von 2007 ^^
www.delphi-forum.de/...w=quizeval&id=64

_________________
Bringe einen Menschen zum grübeln, dann kannst du heimlich seinen Reis essen.
(Koreanisches Sprichwort)
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Do 20.08.09 22:25 
Hey,

user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
(plus ein Leerzeichen)


kommt drauf an wie da er das haben will, weil beim gemorsten Code gibts ja auch keine Leerzeichen. Das Leerzeichen macht die Sache dann bloß beim decodieren einfacher.
€: vergesst was ich gesagt hab, hab das grad mit nem anderen Code verwechselt, beim Morsecode gehts ja gar nich anders...


MfG Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^


Zuletzt bearbeitet von Bergmann89 am Do 20.08.09 22:26, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10184
Erhaltene Danke: 1259

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 20.08.09 22:26 
Moin!

user profile iconBergmann89 hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
(plus ein Leerzeichen)
kommt drauf an wie da er das haben will, weil beim gemorsten Code gibts ja auch keine Leerzeichen. Das Leerzeichen macht die Sache dann bloß beim decodieren einfacher.
Aber sicher gibt´s beim Morsen "Leerzeichen" (=entsprechende Pause). Wie willst du denn sonst jemals den Text wieder entziffern. :lol:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Do 20.08.09 22:27 
Naja Pausen muss es zumindest geben, den wie wollte man sonst I (..) von EE (..) unterscheiden?

_________________
Bringe einen Menschen zum grübeln, dann kannst du heimlich seinen Reis essen.
(Koreanisches Sprichwort)
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Do 20.08.09 22:36 
Ja, hab ich ja auch grad festgestellt. ich hab nur grad an nen Code gedacht, bei dem nur die Blätter des binären Baums belegt sind, und nich zusätzlich noch die Äste (wie es ja beim Morsecode ist). Wäre nur die Blätter des Baumes belegt könnte man das Signal auch ohne Pausen entschlüseln...

MfG Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Fr 21.08.09 09:08 
Auf wikipedia stehn die Pausen soweit ich weis war es ein Leer für Buchstabenanbstand und 2 Leer für Wörter. ^^
turboPASCAL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP / Vischda
D6 PE / D2005 PE
BeitragVerfasst: Fr 21.08.09 12:26 
All zu einfach ist es nicht. ;)

Das sollte etwas Arbeit ersparen:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
function so(Text: string): string;
var
  outText: string;
  i: integer;
begin
  outText := '';
  for i := 1 to length(Text) do
    case UpCase(Text[i]) of
      'A': outText := outText + '|' + '.-';
      'B': outText := outText + '|' + '-...';
      'C': outText := outText + '|' + '-.-.';
      'D': outText := outText + '|' + '—..';
      'E': outText := outText + '|' + '.';
      'F': outText := outText + '|' + '..-.';
      'G': outText := outText + '|' + '--.';
      'H': outText := outText + '|' + '....';
      'I': outText := outText + '|' + '..';
      'J': outText := outText + '|' + '.---';
      'K': outText := outText + '|' + '-.-';
      'L': outText := outText + '|' + '.-..';
      'M': outText := outText + '|' + '--';
      'N': outText := outText + '|' + '-.';
      'O': outText := outText + '|' + '---';
      'P': outText := outText + '|' + '.--.';
      'Q': outText := outText + '|' + '--.-';
      'R': outText := outText + '|' + '.-.';
      'S': outText := outText + '|' + '...';
      'T': outText := outText + '|' + '-';
      'U': outText := outText + '|' + '..-';
      'V': outText := outText + '|' + '...-';
      'W': outText := outText + '|' + '.--';
      'X': outText := outText + '|' + '-..-';
      'Y': outText := outText + '|' + '-.--';
      'Z': outText := outText + '|' + '--..';
      '0': outText := outText + '|' + '-----';
      '1': outText := outText + '|' + '.----';
      '2': outText := outText + '|' + '..---';
      '3': outText := outText + '|' + '...--';
      '4': outText := outText + '|' + '....-';
      '5': outText := outText + '|' + '.....';
      '6': outText := outText + '|' + '----.';
      '7': outText := outText + '|' + '---..';
      '8': outText := outText + '|' + '--...';
      '9': outText := outText + '|' + '-....';
      '.': outText := outText + '|' + '.-.-.-';
      '?': outText := outText + '|' + '..--..';
      '+': outText := outText + '|' + '.-.-.';
      '-': outText := outText + '|' + '-....-';
      '=': outText := outText + '|' + '-...-';
      #32: outText := outText + #32;


"|" fungiert hierbei als Wortpause

      else outText := outText + '';  // alle anderen Zeichen werden nicht übersetzt 
    end;
  // erstes Leerzeichen im outText-String entfernen  
  Delete(outText, 11);
  Result := outText;
end;
Einloggen, um Attachments anzusehen!
_________________
Nein, ich bin nicht der turboPASCAL aus der DP, ich seh nur so aus... :P
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Fr 21.08.09 16:17 
Schreib ihm doch nicht den ganzen Fertigen Quellcode :nut:
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Fr 21.08.09 16:29 
user profile iconturboPASCAL hat folgendes geschrieben Zum zitierten Posting springen:
All zu einfach ist es nicht. ;)

Genau. Und beim Vorlegen des gesamten Quellcodes ist der Lerneffekt IMHO sehr klein. :wink:

Ich würde ja den String beim Morse->Latein von vorne nach hinten durchgehen. Ich weiß nicht, in wie weit es beim Morsen Kollisionen gibt, aber ich denke, dass das nicht ausbleiben wird. Latein->Morse lässt sich ja am Einfachsen wirklich mit StringReplace() umwandeln umwandeln.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 480

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 21.08.09 16:30 
Naja, der komplizierte Teil (das Dekodieren) fehlt ja komplett. Deswegen hab ich das ja auch mit StringReplace machen wollen - da geht das in beiden Richtungen gleich. :D

_________________
We are, we were and will not be.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Fr 21.08.09 16:36 
Hi :)

In Schulen wird zum Entschlüsseln von Morsecode meißt ein Binärbaum verwendet. Ohne weitere Information, welches Verfahren denn hier gewünscht ist, können wir aber wohl kaum richtig helfen.

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)