The 23-year-old also said he had received a list on WhatsApp of all the soldiers who had been promoted to sergeant, including 15 in the Special Forces.
Special Forces soldiers are known as the “protected population” of the Army – but Mr Khalife explained how he could identify their first names by typing their surnames into an Army leave-booking system.
“You would put in a last name and a very long list of information would come out. A clear flaw,” he said.
The jury heard Mr Khalife thought British security services would be “impressed” by what he had found.
“I was the only person in the Ministry of Defence who discovered this flaw,” he claimed, adding that he had only searched the names of seven officers.
“It was a way of advertising my skillset.”
Prosecutors allege Mr Khalife was paid by the Iranian intelligence service for secret information gathered when he was in the Army.
Mr Khalife said he had “always had a gift for exposing flaws in security”.
On Wednesday, the jury heard, aged 15, Mr Khalife used a powerful magnet to remove shop security tags and got into trouble with the police for shoplifting.
Mr Khalife denies collecting information and sending it to an enemy, namely Iran.
He also denies taking a list of special forces soldiers that could be useful to terrorists, perpetrating a bomb hoax at his barracks and escaping from Wandsworth Prison.
His evidence and the trial continue.